Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory Structure

Status
Not open for further replies.

Wiszh

Programmer
Aug 3, 2000
134
US
I'm trying to get java to give me a listing of all files (and directories) in a given directory. How can I access such a tree. (The IO package only seems to help if you want a specific file.<br>Thanx in advance
 
You have to use a recursive method to parse down the directory tree, something like this:<br><br>/**<br> This method processes the directory structure recursively and creates a vector object containing the results.<br> @param dir the directory name to search<br> @param fl the current directory listing<br> */<br><br> public void processADir(String dir, String[] fl)<br> {<br> <br> File f;<br> <br> int i = 0;<br><br> if (fl != null)<br> {<br> while (i &lt; fl.length)<br> {<br> f = new File(dir,fl<i>);<br><br> if (f.isDirectory()){<br> processADir(f.getPath(),f.list());<br> <br> }<br> else<br> files.add(f);<br> i++; <br> }<br> }<br> <br> }<br><br><br>Good Luck..... <p>Troy Williams B.Eng.<br><a href=mailto:fenris@hotmail.com>fenris@hotmail.com</a><br><a href= > </a><br>
 
Thanks, that is something like what I wanted, but the main issue is finding the names of the files in the subdirectory. I did some more research and found that file.list( ) is the function that I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top