To Get List names and Paths of all the Files inside a root folder. Below Code recursively traverse every folder and sub folders and print full path with name of the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public static void main(String[] args) throws IOException { String s_root_path = "<Enter Your Root Folder Path here>"; // String s_root_path = "C:/temp"; get_file_name(s_root_path); }//end Main public static void get_file_name(String s_path){ File folder = new File(s_path); File[] listoffiles = folder.listFiles(); for (int i=0;i<listoffiles.length;i++){ if (listoffiles[i].isDirectory()){ get_file_name(listoffiles[i].getAbsolutePath()); }else if (listoffiles[i].isFile()){ System.out.println(listoffiles[i].getParent() + "\\" + listoffiles[i].getName()); }//end else if }//end for }//end Method |