-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource2_.java
More file actions
80 lines (80 loc) · 2.96 KB
/
Source2_.java
File metadata and controls
80 lines (80 loc) · 2.96 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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Source2_ {
static String PROJECT_NAME = "E:\\KMMicro-Platform\\Src\\trunk";
static String fromStr = PROJECT_NAME;//C:\Users\keving.yang\Desktop\demo\javacopy
static String toStr = "E:\\backup";
static String[] ENCODE_FILES = { "^.*\\.sln$", "^.*\\.csproj$", "^.*\\.cs$", "^.*\\.suo$" };
static String[] EXCLUDE_FOLDERS = { "^\\.svn$","^bin$","^obj$","^log$","^saveFiles$","^saveFiles$" };
public static void main(String[] args) throws Exception {
File fromFile = new File(fromStr);
copy(fromFile);
}
static void copy(File file) throws Exception {
if (file.isDirectory()) {
File[] files = getSubFile(file);
for (File f : files) {
copy(f);
}
if (files.length == 0) {
String fromAbs = file.getAbsolutePath();
String toAbs = fromAbs.replace(fromStr, toStr);
File toFile = new File(toAbs);
if (!toFile.exists()) {
toFile.mkdirs();
}
}
} else {
String fromAbs = file.getAbsolutePath();
System.out.println(fromAbs);
String toAbs = fromAbs.replace(fromStr, toStr);
boolean isChange = false;
for (String reg : ENCODE_FILES) {
if (toAbs.toLowerCase().matches(reg)) {
isChange = true;
break;
}
}
if (isChange) {
toAbs = toAbs + "_";
}
System.out.println(toAbs);
File toFile = new File(toAbs);
if (!toFile.getParentFile().exists()) {
toFile.getParentFile().mkdirs();
}
// "cmd /c copy Test.c Test.txt"
String cmd1 = "cmd /c copy " + fromAbs + " " + toAbs;
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(cmd1);
println(process.getInputStream());
}
}
static void println(InputStream input) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(input, "gbk"));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
input.close();
}
static File[] getSubFile(File file) {
return file.listFiles(new FileFilter() {
public boolean accept(File pathname) {
boolean ret = true;
if (pathname.isDirectory()) {
for (String reg : EXCLUDE_FOLDERS) {
if (pathname.getName().toLowerCase().matches(reg)) {
ret = false;
break;
}
}
}
return ret;
}
});
}
}