-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileInfo.java
More file actions
67 lines (56 loc) · 1.67 KB
/
FileInfo.java
File metadata and controls
67 lines (56 loc) · 1.67 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
import java.io.File;
import java.util.Vector;
class FileInfo {
public File getFile() {
return this.file;
}
private final File file;
private final String matchName;
public String getMatchName() {
return this.matchName;
}
public FileInfo(File aFile) {
this.file = aFile;
this.matchName = GetMatchName(aFile);
}
public static String GetMatchName(File aFile) {
String name = aFile.getName();
return GetMatchName(name);
}
public static String GetMatchName(String name) {
int index = name.lastIndexOf('.');
if (index > 0 && index <= name.length() - 2) {
return name.substring(0, index);
}
return "";
}
/*
* search for files with same matchname in the same directory as itself.
* this is usually used for finding a xmp file to a nef file
* we want the file itself returned also
*/
public Vector<File> GetSiblings(File otherDir) {
Vector<File> ret = new Vector<File>();
File[] files;
if (otherDir.isDirectory()) {
files = otherDir.listFiles();
} else {
files = otherDir.getParentFile().listFiles();
}
for (File aFile : files) {
if (this.IsMatch(aFile)) {
ret.add(aFile);
}
}
return ret;
}
public Boolean IsMatch(FileInfo other) {
return this.matchName.equals(other.matchName);
}
public Boolean IsMatch(File other) {
return this.matchName.equals(GetMatchName(other));
}
public String GetString() {
return this.file.getName() + " >> " + this.matchName;
}
}