-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDirWalk.java
More file actions
42 lines (34 loc) · 778 Bytes
/
Copy pathDirWalk.java
File metadata and controls
42 lines (34 loc) · 778 Bytes
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
40
41
42
import java.io.*;
public class DirWalk {
public static int dirwalk(String path)
{
String[] dirlist = (new File(path)).list();
int total = 0;
if (dirlist == null) {
return 0;
}
for (int i=0; i < dirlist.length; i++) {
String filename = dirlist[i];
if (filename.equals(".") || filename.equals("..")) {
continue;
}
String fullpath=path + "/" + filename;
File newfile = new File(fullpath);
if (newfile.isDirectory()) {
total += dirwalk(fullpath);
}
else {
total++;
}
}
return total;
}
public static void main(String args[])
{
int total;
String dirname = args[0];
System.out.println("Java Traversing: " + args[0]);
total = dirwalk(args[0]);
System.out.println("Java Total Files: " + total);
}
}