Skip to content

Instantly share code, notes, and snippets.

@davetownsend
Created November 26, 2014 15:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davetownsend/85b25e2d2cf342eb46af to your computer and use it in GitHub Desktop.
Save davetownsend/85b25e2d2cf342eb46af to your computer and use it in GitHub Desktop.
Bulk file re-name with Groovy script
// 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