Skip to content

Instantly share code, notes, and snippets.

@Nate-Wessel
Created August 28, 2018 19:30
Show Gist options
  • Save Nate-Wessel/075a7c4027b2512b939d0b4b07f59ecd to your computer and use it in GitHub Desktop.
Save Nate-Wessel/075a7c4027b2512b939d0b4b07f59ecd to your computer and use it in GitHub Desktop.
Python3 batch file rename
import os
from_path = '/home/nate/Dropbox/muni-17477/'
to_path = '/home/nate/Dropbox/muni-17477-fixed/'
old_files = os.listdir(from_path)
for old_file in old_files:
old_fpath = from_path+old_file
with open(old_fpath,'r') as fp:
old_content = fp.read()
old_hour = old_file[11:13]
new_hour =str(int(old_hour)-3)
new_hour = new_hour.zfill(2)
new_file = old_file[:11]+new_hour+old_file[13:]
with open(to_path+new_file,'w+') as newfp:
newfp.write(old_content)
print(new_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment