Searching folders inside folders in java

Discussion in 'Software' started by refresher, Jan 29, 2006.

  1. refresher

    refresher Private E-2

    I have written code to recursively go through a directory and analyse the files within it. The directory i am searching is within another directory containing other folders. What i want to do is extend the code i have written so that it will search each of the outer directories

    File dir = new File("directoryPath/directory1");
    String filename1 = "directoryPath/directory1/file1";
    List list1 = readFile(filename1);
    List list2;
    int count = 0;
    List max = new ArrayList();

    if (dir.isDirectory ()) {
    String[] children = dir.list();
    for (int i=0; i<children.length; i++) {
    count++;
    list2 = readFile(dir + "\\" + children);
    ...... do things here

    }

    }

    So in the above example, i am searching files in directorypath/directory1, but directorypath also contains other directories which i also want to search. Does anybody know how i might do this? Any help would be greatly appreciated
    Thanks!
     
  2. zethon

    zethon Private E-2

    I don't see any recursion in that code. If you used recursion (correctly) it'd be able to do what you're trying to do.

    ----------------------
    Another Message Board
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds