• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Directory List from Parent Directory

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Under Parent directory we have list of subdirectories.
E.g.
C:/xyz/abc
/123
/hello
/test
/images
Drive name & main directory(xyz) name can be changed by user anytime. How can I get list of sub directory from main directory?
Thanks
Angela
 
Jaunty John
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela,
As far as I know (I could be wrong!!!) the drive name (C:\) cannot be changed, at least on Win32 platform. Win32 requires a C:\ root..., and can have any number of other drives.
On *nix platform, root = '/', and can have only that one root.
The snippet of code below is from a program I cobbled together some time ago. If you want all the code email me. Otherwise this may be enough to solve your problem. This code is from the constructor of a JTree object.
Try javax.swing.tree.DefaultMutableTreeNode
as in
previous code...
//The ROOT
DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "MyROOT"));
//Additional ROOTS on Win32, *NIX ROOT='/'
DefaultMutableTreeNode node;
File[] roots = File.listRoots();
for (int k=0; k<roots.length; k++) {
node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k])));
top.add(node);
node.add(new DefaultMutableTreeNode( new Boolean(true) ));
}
...continuing code
JohnB
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!