* improved handling of disk folders in scripting

This commit is contained in:
Reinhard Pointner 2013-04-10 10:55:44 +00:00
parent bb38864e69
commit b21a5d46e8
3 changed files with 12 additions and 5 deletions

View File

@ -1,5 +1,6 @@
// File selector methods
import static groovy.io.FileType.*
import static groovy.io.FileVisitResult.*
// MediaDetection
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() }
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) }
File.metaClass.eachMediaFolder = { c -> getFolders{ it.hasFile{ it.isVideo() } }.each(c) }
List.metaClass.eachMediaFolder = { c -> getFolders{ it.hasFile{ it.isVideo() } }.each(c) }
File.metaClass.eachMediaFolder = { c -> delegate.getMediaFolders().each(c) }
List.metaClass.eachMediaFolder = { c -> delegate.findResults{ it.getMediaFolders() }.flatten().unique().each(c) }
// File utility methods

View File

@ -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) {
if (!filter.accept(file))
return false;
}
return true;
}

View File

@ -6,8 +6,11 @@
def target = tryQuietly{ target } ?: 'file' // target files by default
args.eachMediaFolder {
if (it.isDisk())
return rename(file:it) // rename disk folders instead of files regardless of mode
switch(target) {
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
}
}