Skip to content

Instantly share code, notes, and snippets.

@davetownsend
Created November 26, 2014 15:25
Show Gist options
  • Save davetownsend/85b25e2d2cf342eb46af to your computer and use it in GitHub Desktop.
Save davetownsend/85b25e2d2cf342eb46af to your computer and use it in GitHub Desktop.

Revisions

  1. davetownsend created this gist Nov 26, 2014.
    11 changes: 11 additions & 0 deletions rename.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // 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}")
    }