Getting Dir structure of computer into a JTree
I need help with reading the full directory structure of a computer [ just mainly identifying the directoreis and placing them into a JTree. I can identify files within a directory. I just need help locating all the directories, subdirectories, and so of the computer. Planning to place the full works into the JTree for browsing.
[344 byte] By [
mattcrist] at [2007-9-27 14:42:56]

Not sure what you're planning to do with a JTree structure of the directory structure but if browsing is all you need then either a simple or some derived version of JFileChooser might do the trick. It can be manipulated in all sorts of ways to filter and restrict the uses.
Just an idea. Hope it helps.
I am getting the full directory structure of a computer [C:\, D:\, etc...] all the files and all the directories and putting them into a JTree. I am currently using JFileChooser, but I do not wish to use this much longer, because I really like the look of the JTree over the JFileChooser
The following is a recursive directory search I use to find all the PDFs, starting from a specified directory. The addToFileTable method just puts the result in a HashMap. If you were to track the level of the hierarchy by passing in an int to the method, or perhaps the current node of the tree, you could easily modify this to populate a tree.
protected void scanDirectories( File dir ){
logger.debug("Scanning: " + dir);
File[] files = dir.listFiles();
for( int i = 0; i < files.length; i++ ) {
File file = files[i];
logger.debug( "Current file(" + i + "): " + file );
if( file.isDirectory() ){
// deal with a directory
scanDirectories(file);
}
else{
// deal with a file
String path = file.getAbsolutePath();
if( path.endsWith(".pdf") ){
addToFileTable( "pdf", path );
}
}
}
}
When i was student i wrote JTree programe with for displaying dir structure, if you want then i will send you, not today but tommorrow.if you want then send me mail at : Y_NOT@www.com
Y_NOT at 2007-7-5 22:42:47 >

File.listRoots() gives you an array of Files, one for each drive on your system. You can then explore the entries (both directories and files) in each instance of the File array by using list()
You can use this information to create your TreeModel that JTree will query to display information.