WebHosting

Showing posts with label java list all files in directory. Show all posts
Showing posts with label java list all files in directory. Show all posts

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;
    }


Featured Posts

How to Enable and Configure Remote Desktop (RDP) on Ubuntu 24.04.4 LTS

Remote Desktop Protocol (RDP) support in Ubuntu has become considerably easier with the GNOME Remote Desktop stack included in modern Ubuntu...