-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFileExtensions.pde
54 lines (43 loc) · 1.37 KB
/
FileExtensions.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
static class FileExtensions {
static String getExtension(File file) {
return getExtension(file.getName());
}
static String getExtensionLowerCase(File file) {
return getExtensionLowerCase(file.getName());
}
static String getExtension(String file) {
int idx = file.lastIndexOf('.');
if (idx > 0) {
return file.substring(idx+1);
}
return null;
}
static String getExtensionLowerCase(String file) {
String extension = getExtension(file);
if (extension != null) {
return extension.toLowerCase();
}
return extension;
}
static String getFolder(String file) {
int slash = file.lastIndexOf("/");
return slash != -1 ? file.substring(0, slash) : file;
}
static String getFolder(File file) {
return getFolder(file.getAbsolutePath());
}
static String getFileName(String file) {
int slash = file.lastIndexOf("/");
return slash != -1 ? file.substring(slash) : file;
}
static String getFileName(File file) {
return file.getName();
}
static String getFileNameWithoutExtension(File file) {
return getFileNameWithoutExtension(file.getName());
}
static String getFileNameWithoutExtension(String file) {
int dot = file.lastIndexOf(".");
return dot != -1 ? getFileName(file).substring(0, dot) : file;
}
}