Skip to content

Instantly share code, notes, and snippets.

@nemo-kaz
Created January 12, 2014 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemo-kaz/8391498 to your computer and use it in GitHub Desktop.
Save nemo-kaz/8391498 to your computer and use it in GitHub Desktop.
Remove space and special character from file name
// File Space Renamer
// Renames any file which has %20 %40 (space) : ;
// %20 -> _
// %40 -> @
// (space) -> _
// eg "Hello World.txt%40" -> "Hello_World@.txt"
new File(".").eachFile { file ->
if(file.isFile()){
curName = file.getPath().replaceAll(/.\\(.*)/) {m0,m1 -> m1}
newFileN = URLDecoder.decode(curName, "UTF-8").replaceAll(/%20/,"_").replaceAll(/%40/,"@").replaceAll(/ /,"_").replaceAll(/:/,"_").replaceAll(/;/,"_")
if (newFileN != curName) {
newName = new File(URLDecoder.decode(curName, "UTF-8"))
println "現行ファイル名: "+curName
println "新規ファイル名: "+newFileN
file.renameTo(new File(newFileN))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment