Created
November 26, 2014 15:25
-
-
Save davetownsend/85b25e2d2cf342eb46af to your computer and use it in GitHub Desktop.
Bulk file re-name with Groovy script
This file contains hidden or 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
// needed to rename over 900 files in a dir from a pattern like | |
// noa_6989589000_201404080445010001.pdf to NAR6989589000.pdf where the 6989589000 part | |
// (different on every file) is the needed in the new file. | |
// simply run from the CLI: groovy rename.groovy | |
dir = "/path to files" | |
def pre = "NAR", ext = ".pdf" | |
new File(dir).eachFile() { f -> | |
def name = f.name.split('_')[1] | |
f.renameTo("${pre}${name}${ext}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment