forked from natural/java2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSantAmoc
More file actions
80 lines (79 loc) · 2.63 KB
/
SantAmoc
File metadata and controls
80 lines (79 loc) · 2.63 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package response;
import java.io.File;
/**
* Contains some methods to list files and folders from a directory
*
* @author SanT AmoC ShiS
*/
public class ListFilesUtil {
/**
* List all the files and folders from a directory
* @param directoryName to be listed
*/
public void listFilesAndFolders(String directoryName){
File directory = new File(directoryName);
//get all the files from a directory
int fileCounter = 0;
File[] fList = directory.listFiles();
for (File file : fList){
System.out.println(file.getName());
fileCounter ++;
}
System.out.println("Total File Count :"+fileCounter);
}
/**
* List all the files under a directory
* @param directoryName to be listed
*/
public void listFiles(String directoryName){
File directory = new File(directoryName);
int fileCounter = 0;
//get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList){
if (file.isFile()){
System.out.println(file.getName());
fileCounter ++;
}
}
System.out.println("Total File Count :"+fileCounter);
}
/**
* List all the folder under a directory
* @param directoryName to be listed
*/
public void listFolders(String directoryName){
File directory = new File(directoryName);
//get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList){
if (file.isDirectory()){
System.out.println(file.getName());
}
}
}
/**
* List all files from a directory and its subdirectories
* @param directoryName to be listed
*/
public void listFilesAndFilesSubDirectories(String directoryName){
File directory = new File(directoryName);
//get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList){
if (file.isFile()){
System.out.println(file.getAbsolutePath());
} else if (file.isDirectory()){
listFilesAndFilesSubDirectories(file.getAbsolutePath());
}
}
}
public static void main (String[] args){
ListFilesUtil listFilesUtil = new ListFilesUtil();
//final String directoryLinuxMac ="/Users/loiane/test";
//Windows directory example
final String directoryWindows ="c://Temp";
listFilesUtil.listFiles(directoryWindows);
listFilesUtil.listFilesAndFolders(directoryWindows);
}
}