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 < 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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.