Skip to content

Instantly share code, notes, and snippets.

@Roumenov
Last active March 1, 2020 13:48
Show Gist options
  • Save Roumenov/ba15934055c4365c1437faf02a2db411 to your computer and use it in GitHub Desktop.
Save Roumenov/ba15934055c4365c1437faf02a2db411 to your computer and use it in GitHub Desktop.
primitive procedure to rename a bunch of files that broke with naming convention
import shutil, os
current_directory = os.getcwd()
filename = 'output.txt'
for file in os.listdir(current_directory):
active = file.replace('_idle', '_act')
print(active)
if '_idle' in file and not os.path.isfile(active):
output = file.replace('_idle','_act')
source = file.replace('_idle','')
with open(filename, 'a') as f:
f.write(output)
f.write(",\n")
if os.path.isfile(source):
shutil.copy(source, active)
else:
pass
shutil.copy(file,source)
os.remove(file)
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment