Skip to content

Instantly share code, notes, and snippets.

@hengstchon
Created June 7, 2019 19:56
Show Gist options
  • Save hengstchon/6ee65779f16496279394c782a18ed2b4 to your computer and use it in GitHub Desktop.
Save hengstchon/6ee65779f16496279394c782a18ed2b4 to your computer and use it in GitHub Desktop.
import os
def change_dir(dir):
for root, dirs, files in os.walk(dir):
for f in files:
file_path = os.path.join(root, f)
change_file(file_path)
return
def change_file(filename):
target_suffix = ['mkv', 'mp4', 'webm']
name, suffix = filename.split('.')
if suffix in target_suffix:
new_filename = name[:-12] + '.' + suffix
print('-----begin-----')
print('old: \n', filename)
print('new: \n', new_filename)
print('-----end-------')
print()
os.rename(filename, new_filename)
return
cur_dir = os.getcwd()
change_dir(cur_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment