Created
August 28, 2018 19:30
-
-
Save Nate-Wessel/075a7c4027b2512b939d0b4b07f59ecd to your computer and use it in GitHub Desktop.
Python3 batch file rename
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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