-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentsSubDir.java
More file actions
39 lines (34 loc) · 1.12 KB
/
ContentsSubDir.java
File metadata and controls
39 lines (34 loc) · 1.12 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.File;
public class ContentsSubDir
{
private String fileListString ="List Contents and Sub-Directories: \n";
private String dir;
private File searchDir;
private File[] fileArray;
public ContentsSubDir(String dir) throws NullPointerException
{
this.dir = dir;
this.searchDir = new File(dir);
fileArray = this.searchDir.listFiles();
}
public String listFiles()
{
RecursivePrint(fileArray,0,0);
return fileListString;
}
private void RecursivePrint(File[] fileArray,int index,int level)
{
if(index == fileArray.length)
return;
for (int i = 0; i < level; i++)
fileListString+=("\t");
if(fileArray[index].isFile())
fileListString+=(fileArray[index].getName()+"\n");
else if(fileArray[index].isDirectory())
{
fileListString+=("Folder: " + fileArray[index].getName() + "\n");
RecursivePrint(fileArray[index].listFiles(), 0, level + 1);
}
RecursivePrint(fileArray,++index, level);
}
}