Skip to content

Instantly share code, notes, and snippets.

@aaronsaunders
Created July 23, 2013 07:17
Show Gist options
  • Save aaronsaunders/6060425 to your computer and use it in GitHub Desktop.
Save aaronsaunders/6060425 to your computer and use it in GitHub Desktop.
Batch renaming files in iPython
# infile is 'rename_mapping.txt' tab-sep: oldname newname
# ext of file to be replace can be specified
with open('rename_mapping.txt', 'r') as fh:
map = { line.strip().split()[0]:line.strip().split()[1] for line in fh.readlines() }
oldnames = !ls *.fastq.gz
for oldname in oldnames:
if oldname in map:
newname = map[oldname]
!mv $oldname $newname
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment