Skip to content

Instantly share code, notes, and snippets.

@kitelife
Created March 2, 2013 17:18
Show Gist options
  • Save kitelife/5072050 to your computer and use it in GitHub Desktop.
Save kitelife/5072050 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os, sys
target_dir = 'output/'
def rename_files(dir_name):
if not dir_name.endswith('/'):
dir_name += '/'
file_names = os.listdir(dir_name)
if not os.path.exists(target_dir):
os.mkdir(target_dir)
name_template = '%s.%s'
count = 1
for filename in file_names:
if not filename.startswith('.'):
file_type = filename.split('.')[-1]
new_name = target_dir + name_template %(str(count), file_type)
print filename, '--->', new_name
os.system('cp "%s" "%s"' %(dir_name + filename, new_name))
count +=1
if __name__ == '__main__':
arg_len = len(sys.argv)
if arg_len != 2:
print 'usage: python rename_all.py dir_name'
else:
rename_files(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment