-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderWatcher.java
More file actions
22 lines (20 loc) · 887 Bytes
/
FolderWatcher.java
File metadata and controls
22 lines (20 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.IOException;
import java.nio.file.*;
/** OS-level watcher for automated indexing. */
public class FolderWatcher {
public static void main(String[] args) throws IOException, InterruptedException {
Path docPath = Paths.get("./docs");
WatchService watchService = FileSystems.getDefault().newWatchService();
docPath.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
System.out.println("Monitoring: " + docPath.toAbsolutePath());
while (true) {
WatchKey key = watchService.take();
for (WatchEvent<?> event : key.pollEvents()) {
Path filename = (Path) event.context();
new ProcessBuilder("./venv/bin/python", "ingest.py", filename.toString())
.inheritIO().start().waitFor();
}
if (!key.reset()) break;
}
}
}