forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher.groovy
33 lines (24 loc) · 870 Bytes
/
watcher.groovy
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
#!/usr/bin/env filebot -script
// --output folder must be a valid folder
outputFolder = _args.absoluteOutputFolder
if (outputFolder == null || !outputFolder.isDirectory() || !outputFolder.canWrite()) {
die "Invalid usage: output folder must exist and must be a writable directory: $outputFolder"
}
// watch folders and process files that were added / modified
def watchman = args[0].watchFolder{ changes ->
// log input files
changes.each{ f -> log.fine "Input: $f" }
// extract archives to output directory
if (_args.extract) {
changes += extract(file: changes.findAll{ it.archive }, output: outputFolder / 'Archive')
}
// rename input files
if (_args.rename) {
rename(file: changes)
}
}
// commit changes after 5s of settle down time
watchman.commitDelay = 5000
watchman.commitPerFolder = true
println "Press ENTER to exit..."
console.readLine()