Results 1 to 3 of 3
  1. #1
    nimraj is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Question How do you recursively traverse through file folders ?

    Hello all,
    How do you recursively traverse through file folders ?
    Or is there any other way to traverse through windows directory structure and bring it into a data structure ?

    Any help is appreciated.:confused:

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.io.File;
    import java.util.*;
    
    public class GatheringFiles {
        public static void main(String[] args) {
            File folder = new File(".");
            List<File> list = new ArrayList<File>();
            getFiles(folder, list);
            System.out.println("list.size = " + list.size());
        }
    
        private static void getFiles(File folder, List<File> list) {
            folder.setReadOnly();
            File[] files = folder.listFiles();
            for(int j = 0; j < files.length; j++) {
                list.add(files[j]);
                if(files[j].isDirectory())
                    getFiles(files[j], list);
            }
        }
    }

  3. #3
    nimraj is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Default Thanks

    thanks hardwired, for the quick and accurate reply.
    This is pretty good, exactly what i needed.:)

Similar Threads

  1. recursively searching through arraylists
    By newtojava7 in forum New To Java
    Replies: 1
    Last Post: 03-17-2008, 03:36 AM
  2. Computing Fibonacci numbers recursively
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-22-2008, 09:20 PM
  3. Replies: 20
    Last Post: 12-17-2007, 04:20 PM
  4. error with traverse a relations ship
    By darkbalder in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 12-11-2007, 06:25 PM
  5. URGENTTT...zip folders in java
    By rach in forum New To Java
    Replies: 3
    Last Post: 08-13-2007, 04:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •