* improved handling of disk folders in scripting
This commit is contained in:
parent
bb38864e69
commit
b21a5d46e8
|
@ -1,5 +1,6 @@
|
||||||
// File selector methods
|
// File selector methods
|
||||||
import static groovy.io.FileType.*
|
import static groovy.io.FileType.*
|
||||||
|
import static groovy.io.FileVisitResult.*
|
||||||
|
|
||||||
// MediaDetection
|
// MediaDetection
|
||||||
import net.sourceforge.filebot.media.*
|
import net.sourceforge.filebot.media.*
|
||||||
|
@ -27,9 +28,10 @@ String.metaClass.getFolders = { c -> new File(delegate).getFolders(c) }
|
||||||
File.metaClass.getFolders = { c -> def folders = []; traverse(type:DIRECTORIES, visitRoot:true) { folders += it }; return c ? folders.findAll(c).sort() : folders.sort() }
|
File.metaClass.getFolders = { c -> def folders = []; traverse(type:DIRECTORIES, visitRoot:true) { folders += it }; return c ? folders.findAll(c).sort() : folders.sort() }
|
||||||
List.metaClass.getFolders = { c -> findResults{ it.getFolders(c) }.flatten().unique() }
|
List.metaClass.getFolders = { c -> findResults{ it.getFolders(c) }.flatten().unique() }
|
||||||
|
|
||||||
|
File.metaClass.getMediaFolders = { def folders = []; traverse(type:DIRECTORIES, visitRoot:true, preDir:{ it.isDisk() ? SKIP_SUBTREE : CONTINUE }) { folders += it }; folders.findAll{ it.hasFile{ it.isVideo() } || it.isDisk() }.sort() }
|
||||||
String.metaClass.eachMediaFolder = { c -> new File(delegate).eachMediaFolder(c) }
|
String.metaClass.eachMediaFolder = { c -> new File(delegate).eachMediaFolder(c) }
|
||||||
File.metaClass.eachMediaFolder = { c -> getFolders{ it.hasFile{ it.isVideo() } }.each(c) }
|
File.metaClass.eachMediaFolder = { c -> delegate.getMediaFolders().each(c) }
|
||||||
List.metaClass.eachMediaFolder = { c -> getFolders{ it.hasFile{ it.isVideo() } }.each(c) }
|
List.metaClass.eachMediaFolder = { c -> delegate.findResults{ it.getMediaFolders() }.flatten().unique().each(c) }
|
||||||
|
|
||||||
|
|
||||||
// File utility methods
|
// File utility methods
|
||||||
|
|
|
@ -306,12 +306,14 @@ public final class FileUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean containsOnly(Iterable<File> files, FileFilter filter) {
|
public static boolean containsOnly(Collection<File> files, FileFilter filter) {
|
||||||
|
if (files.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (!filter.accept(file))
|
if (!filter.accept(file))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,11 @@
|
||||||
def target = tryQuietly{ target } ?: 'file' // target files by default
|
def target = tryQuietly{ target } ?: 'file' // target files by default
|
||||||
|
|
||||||
args.eachMediaFolder {
|
args.eachMediaFolder {
|
||||||
|
if (it.isDisk())
|
||||||
|
return rename(file:it) // rename disk folders instead of files regardless of mode
|
||||||
|
|
||||||
switch(target) {
|
switch(target) {
|
||||||
case 'file' : return rename(folder:it) // rename files within each folder
|
case 'file' : return rename(folder:it) // rename files within each folder
|
||||||
case 'folder' : return rename(file :it) // rename folders as if they were files
|
case 'folder' : return rename(file:it) // rename folders as if they were files
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue