Created
January 12, 2014 22:24
-
-
Save nemo-kaz/8391498 to your computer and use it in GitHub Desktop.
Remove space and special character from file name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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