-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathUtil.pde
63 lines (51 loc) · 1.47 KB
/
PathUtil.pde
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
import java.util.Arrays;
import java.util.Comparator;
String pathJoin(String a, String b) {
return a + CONFIG.pathSeparator + b;
}
String pathJoin(String a, String b, String c) {
return pathJoin(a, b) + CONFIG.pathSeparator + c;
}
StringList listFileNames(String dir) throws NotDirectoryException {
File file = new File(dir);
StringList filenames = new StringList();
if (file.isDirectory()) {
String names[] = file.list();
for (String n : names) {
filenames.append(n);
}
} else {
throw new NotDirectoryException("");
}
return filenames;
}
int extractNumber(String s, char startToken, char endToken) {
int i = 0;
try {
int start = s.indexOf(startToken) + 1;
int end = s.lastIndexOf(endToken);
String number = s.substring(start, end);
i = Integer.parseInt(number);
} catch (Exception e) {
i = 0;
}
return i;
}
StringList listFileNames(String dir, String extention) throws NotDirectoryException {
StringList allfiles = listFileNames(dir);
StringList files = new StringList();
for (String f : allfiles) {
if (f.endsWith(extention)) {
files.append(f);
}
}
return files;
}
String[] sortFilenamesNumerically(StringList files) {
String[] sorted = new String[files.size()];
for (String f : files) {
int index = extractNumber(f, '_', '.') - 1;
sorted[index] = f;
}
return sorted;
}