-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFromParentMain.java
57 lines (51 loc) · 1.43 KB
/
FromParentMain.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
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FromParentMain {
public static void main(String[] args) {
if (args.length < 1) {
System.out.println(" usage: Child_To_Parent_Folder(parent_mode) <dir> ...");
System.exit(0);
}
for (String path : args) {
try {
DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(path));
for (Path file : stream) {
if (file.toFile().exists()) {
// for directories
if (file.toFile().isDirectory()) {
try {
new ChildToParent(file);
} catch (IOException e) {
System.out.println("Error opening " + path);
e.printStackTrace();
}
}
// for files
if (file.toFile().isFile()) {
try {
Files.move(file, Paths.get(path).resolve(file.getFileName()));
} catch (IOException e) {
System.out.println(file.toString() + " couldn't be moved");
e.printStackTrace();
}
}
} else
System.out.println(path + " doesn't exists!");
}
} catch (IOException e) {
System.out.println("Failed to get files and folders from " + path);
e.printStackTrace();
}
}
System.out.println("Completed!");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
System.out.println("Unable to sleep thread");
e.printStackTrace();
}
}
}