-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileSyncerUtils.java
More file actions
73 lines (68 loc) · 2.72 KB
/
FileSyncerUtils.java
File metadata and controls
73 lines (68 loc) · 2.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
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.AbstractCollection;
import java.util.Vector;
class FileSyncerUtils {
public static boolean doChecking(AbstractCollection master, File slaveDirFile, File targetDirFile, IMessageDisplay outputArea) {
if (master == null) {
outputArea.showMessage("master information ist leer (null)\n");
return false;
}
if (master.size() <= 0) {
outputArea.showMessage("master information ist leer\n");
return false;
}
if (!slaveDirFile.isDirectory()) {
outputArea.showMessage("slave-verzeichnis existiert nicht oder ist kein verzeichnis\n");
return false;
}
if (!targetDirFile.isDirectory()) {
targetDirFile.mkdirs();
outputArea.showMessage("ziel-verzeichnis erstellt\n");
if (!targetDirFile.isDirectory()) {
outputArea.showMessage("ziel-verzeichnis existiert nicht oder ist kein verzeichnis\n");
}
return false;
}
return true;
}
public static void doCopying(Vector<File> toCopy, File targetDirFile, IMessageDisplay outputArea) {
outputArea.showMessage("starte kopieren von " + toCopy.size() + " dateien\n");
int current = 0;
for (File f : toCopy) {
try {
current++;
outputArea.showMessage(" cp " + current + "/" + toCopy.size() + " :" + f.getName() + " \n");
FileUtils.copyFileToDirectory(f, targetDirFile);
} catch (IOException e) {
outputArea.showMessage("fehler beim kopieren von:" + f.getName() + "\n");
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
public static Vector<FileInfo> GetFileInfoItems(String absPath, String[] extensions) {
Vector<FileInfo> ret = new Vector<FileInfo>();
for (FileInfo aFile : GetFileInfoItems(absPath)) {
boolean extMatch = false;
for (String ext : extensions) {
extMatch |= aFile.getFile().getName().toLowerCase().endsWith(ext.toLowerCase());
}
if (extMatch) {
ret.add(aFile);
}
}
return ret;
}
public static Vector<FileInfo> GetFileInfoItems(String absPath) {
Vector<FileInfo> ret = new Vector<FileInfo>();
File f = new File(absPath);
if (f.exists() && f.isDirectory()) {
File[] files = f.listFiles();
for (File aFile : files) {
ret.add(new FileInfo(aFile));
}
}
return ret;
}
}