Created
October 10, 2013 14:32
-
-
Save saulovenancio/6919365 to your computer and use it in GitHub Desktop.
iterate all files and subfolders in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
public class DirectoryReader { | |
static int spc_count=-1; | |
static void Process(File aFile) { | |
spc_count++; | |
String spcs = ""; | |
for (int i = 0; i < spc_count; i++) | |
spcs += " "; | |
if(aFile.isFile()) | |
System.out.println(spcs + "[FILE] " + aFile.getName()); | |
else if (aFile.isDirectory()) { | |
System.out.println(spcs + "[DIR] " + aFile.getName()); | |
File[] listOfFiles = aFile.listFiles(); | |
if(listOfFiles!=null) { | |
for (int i = 0; i < listOfFiles.length; i++) | |
Process(listOfFiles[i]); | |
} else { | |
System.out.println(spcs + " [ACCESS DENIED]"); | |
} | |
} | |
spc_count--; | |
} | |
public static void main(String[] args) { | |
String nam = "D:/"; | |
File aFile = new File(nam); | |
Process(aFile); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment