forked from dionboles/javaFileCopying
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_testing.java
69 lines (58 loc) · 2.14 KB
/
file_testing.java
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
package copyFilesGo;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import org.apache.commons.io.FileUtils;
class Filewalker {
JFrame frame = new JFrame();
JProgressBar bar = new JProgressBar();
int Counter = 0;
public void CopyDirectoryRecursively(Path sourceDir, Path destinationDir) throws IOException {
bar.setValue(0);
bar.setBounds(0, 0, 420, 50);
bar.setStringPainted(true);
frame.add(bar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(420, 420);
frame.setLayout(null);
frame.setVisible(true);
Files.walk(sourceDir).forEach(sourcePath -> {
try {
Path targetPath = destinationDir.resolve(sourceDir.relativize(sourcePath));
System.out.printf("Copying %s to %s%n", sourcePath, targetPath);
File sourcFile = new File(sourcePath.toString());
File targetFile = new File(targetPath.toString());
FileUtils.copyDirectory(sourcFile, targetFile);
System.out.println(Counter);
if ((Counter % 10) == 0) {
bar.setValue(Counter);
}
Counter += 1;
} catch (IOException e) {
System.out.format("I/O error: %s%n", e);
// TODO: handle exception
}
});
}
}
/**
* main
*/
public class App {
public static void main(String[] args) {
Path sourceDir = Paths.get("/Users/dionboles/Documents");
Path destinationDir = Paths.get(
"/Users/dionboles/Library/Containers/com.wdc.WDDesktop.WDDesktopFinderSync/Data/volumes/e161eba9-2a6b-4d7c-af87-31f627c83d7f/Dion's My Cloud Home/Coding");
try {
Filewalker file_walker = new Filewalker();
file_walker.CopyDirectoryRecursively(sourceDir, destinationDir);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}