How to search all the local disks and list all the files present in the disk? how to detect the removable disk, so that i can search removable disks also. i will be helpfull if i can get a code snippet. thank u in advance.
Printable View
How to search all the local disks and list all the files present in the disk? how to detect the removable disk, so that i can search removable disks also. i will be helpfull if i can get a code snippet. thank u in advance.
There are several reasons why you may not be able to do this:
protected locations, and the many different ways different OS's organize drives. Protected locations are impossible to access without hacking (possible legal issues here) or having all the passwords/access rights. OS files as well as many Virus Protection Software files have vastly restricted access, as well as any files that a certain user wishes to mark as protected.
I have a method for this, however it will take you a very long time depending on the number of files you have on your disk.
WARNING: Use with caution
Code :public static List<File> listFiles(final String path, final boolean recursive) { final List<File> files = new ArrayList<File>(); final File startPath = new File(path); if (startPath != null && startPath.listFiles() != null) { for (final File file : startPath.listFiles()) { if (file.isDirectory() && recursive) { files.addAll(listFiles(file.getAbsolutePath(), recursive)); } else if (file.isFile()) { files.add(file); } } } return files; }
And to invoke this with your drive root, call it like this.
Code :final List<File> files = listFiles(File.separator, true);
// Json
The first code block is the actual method which will call itself, the second code block is the line of code which will start the process off.
// Json