WebHosting

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

เค•िเคธเค•े เคนिเคธ्เคธे เคฎें เคฎें เคฏे เคงเคฐเคคी

เคšिเคก़िเคฏों เค•ा เค˜เคฐ เคœเคฒ เคฐเคนा เคนै  เค‡ंเคธाเคจ เค–ुเคถ เคนै เค•ि เคฏे เค†เค— เคฆूเคฐ เคนै เค…เคญी เค•เคญी เคคो เค†เคเค—ी เค˜เคฐ เคคเค•  เคคेเคฐा เคญी เค˜เคฐ เคœเคฒेเค—ा เค•เคญी เคฌेเคœुเคฌाเคจ เคนै เค•ुเค› เคฌोเคฒเคคे เคจเคนीं เคนै เคฆिเคฒ เคฎें เคฆुเค– ...