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

#Intel #Core #i9 #Processors: A Breakdown

Intel Core i9 Processors: A Breakdown Intel's 14th Gen Core i9 series offers a range of processors designed for various use cases. Her...