-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScriptTagGen.java
More file actions
112 lines (86 loc) · 3.72 KB
/
ScriptTagGen.java
File metadata and controls
112 lines (86 loc) · 3.72 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import java.io.File;
/**
* Contains some methods to list files and folders from a directory
*
* @author Loiane Groner
* http://loiane.com (Portuguese)
* http://loianegroner.com (English)
*/
class ScriptTagGen {
/**
* 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
File[] fList = directory.listFiles();
for (File file : fList){
System.out.println(file.getName());
}
}
/**
* List all the files under a directory
* @param directoryName to be listed
*/
public void listFiles(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.getName());
}
}
}
/**
* 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, int length, String prefix, String postfix, String type) throws Exception{
File directory = new File(directoryName);
//get all the files from a directory
File[] fList = directory.listFiles();
for (File file : fList){
if (file.isFile()){
String fname = file.getCanonicalPath();
fname = fname.substring(length);
if(fname.indexOf(type)>0){
System.out.println(prefix + fname + postfix);
}
} else if (file.isDirectory()){
listFilesAndFilesSubDirectories(file.getAbsolutePath(), length, prefix, postfix, type);
}
}
}
public static void main (String[] args) throws Exception{
ScriptTagGen listFilesUtil = new ScriptTagGen();
final String directoryLinuxMac = args[0];
System.out.println("\n\n<!-- Modules -->\n");
listFilesUtil.listFilesAndFilesSubDirectories(directoryLinuxMac, directoryLinuxMac.length(), "<script src=\"", "\"></script>", ".module.js");
System.out.println("\n\n<!-- Factories -->\n");
listFilesUtil.listFilesAndFilesSubDirectories(directoryLinuxMac, directoryLinuxMac.length(), "<script src=\"", "\"></script>", ".factory.js");
System.out.println("\n\n<!-- Services -->\n");
listFilesUtil.listFilesAndFilesSubDirectories(directoryLinuxMac, directoryLinuxMac.length(), "<script src=\"", "\"></script>", ".service.js");
System.out.println("\n\n<!-- Directives -->\n");
listFilesUtil.listFilesAndFilesSubDirectories(directoryLinuxMac, directoryLinuxMac.length(), "<script src=\"", "\"></script>", ".directive.js");
System.out.println("\n\n<!-- Controllers -->\n");
listFilesUtil.listFilesAndFilesSubDirectories(directoryLinuxMac, directoryLinuxMac.length(), "<script src=\"", "\"></script>", ".controller.js");
System.out.println("\n\n<!-- HTML Templates -->\n");
listFilesUtil.listFilesAndFilesSubDirectories(directoryLinuxMac, directoryLinuxMac.length(), "", "", ".html");
}
}