Skip to content

Instantly share code, notes, and snippets.

@marcelmaatkamp
Created March 21, 2010 09:57
Show Gist options
  • Save marcelmaatkamp/339194 to your computer and use it in GitHub Desktop.
Save marcelmaatkamp/339194 to your computer and use it in GitHub Desktop.
#!/usr/bin/env groovy
import java.util.regex.Pattern
# Older versions of sabnzb created a folder structure like this
# /complete/4323322/<item>.mp3
# /complete/4564334/<item>.mkv
#
# This script will traverse these directories, move the contents
# into the specified folder and remove empty directories:
# /complete/music/<item>.mp3
# /complete/video/<item>.mkv
#
# @author: marcel maatkamp (m.maatkamp avec gmail)
[
"images" : ["jpg","gif","bmp"],
"movies" : ["wmv","avi","mov","mkv","mpg4","mp4.*","m4v","mpg"],
"music" : ["mp3","wav","flac","m3u", "cue"],
"books" : ["pdf","djv", "djvu","chm"],
"dvds" : ["iso"],
"nzb" : ["nzb","nfo","sfv"],
"other" : ["nfo","log","txt","par2"]
].each { type ->
new File(type.key).mkdir()
type.value.each { extention ->
new File("./").eachDirMatch(~/[0-9].*/) { dir ->
def dirClos
dirClos = {
println "Dir ${it.canonicalPath}";
it.eachDir( dirClos )
it.eachFileMatch(Pattern.compile(/.*.${extention}/, Pattern.CASE_INSENSITIVE)) { file ->
file.renameTo(new File("./${type.key}/"+file.name))
}
if(it.list().toList().empty) {
it.delete()
}
}
dirClos(dir)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment