Friday, March 30, 2012

Get list of all files in a directory : java Recursively


 public static ArrayList<String> files=new  ArrayList<String>();
    public static ArrayList<String> ReturnAllFileFromAFolder(String FolderPath)
    {
       
        File folder = new File(FolderPath);
    File[] listOfFiles = folder.listFiles();

    for (int i = 0; i < listOfFiles.length; i++) {
      if (listOfFiles[i].isFile()) {
       // System.out.println("File " + listOfFiles[i].getName());
        files.add(FolderPath+"/"+listOfFiles[i].getName());
      } else if (listOfFiles[i].isDirectory()) {
       // System.out.println("Directory " + listOfFiles[i].getName());
        //files.add(FolderPath+"/"+listOfFiles[i].getName());
        ReturnAllFileFromAFolder( FolderPath+"/"+listOfFiles[i].getName());
      }
    }
    return files;
    }


No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc

 #Linux Commands Unveiled: #date, #uname, #hostname, #hostid, #arch, #nproc Linux is an open-source operating system that is loved by millio...