-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigFileReader.java
More file actions
67 lines (63 loc) · 2.07 KB
/
Copy pathConfigFileReader.java
File metadata and controls
67 lines (63 loc) · 2.07 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
package file_organizer_gui;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
import javax.swing.JOptionPane;
import directory_watching.DirectoryWatcher;
public class ConfigFileReader {
Scanner inputStream;
DirectoryWatcher watcher;
public void readConfig() {
String line = "";
String[] lineSplit;
String watchDirectory;
FileMoverSetUp setUp = new FileMoverSetUp();
String moveDirectory;
String fileType;
try {
watcher = new DirectoryWatcher();
inputStream = new Scanner(new FileReader("config.txt"));
while(inputStream.hasNextLine()) {
line=inputStream.nextLine();
if(line.charAt(0)=='#' || line == null || line.equals("open_space")) {
continue;
}
else {
lineSplit=line.split(",");
if(lineSplit[0].equals("WATCH") && lineSplit.length==3) {
watchDirectory = lineSplit[1];
Path watchPath = Paths.get(watchDirectory);
if(lineSplit[2].equals("Recursive")) {
DirectoryValidator.validate(watchPath);//See if the path is valid
watcher.registerAll(watchPath);//register path recursively
System.out.println( watchPath + " registered recursively");
}
else {
DirectoryValidator.validate(watchPath);//See if path is valid
watcher.register(watchPath);//register path non-recursively
System.out.println(watchPath + " registered non-recursively");
}
}
else if(lineSplit[0].equals("MOVE") && lineSplit.length==3) {
moveDirectory = lineSplit[1];
fileType = lineSplit[2];
Path movePath = Paths.get(moveDirectory);
setUp.registerFileType(movePath, fileType);
System.out.println(fileType + " move path registered");
}
}
}
}
catch(DirectoryNotFoundException e) {
e.getExceptionPopUp();
}
catch(IOException e) {
JOptionPane.showMessageDialog(null, "Something has gone wrong with config file registration, please restart the program.", "Error", JOptionPane.INFORMATION_MESSAGE);
}
}
public DirectoryWatcher getWatcher() {
return watcher;
}
}