Created
June 7, 2019 19:56
-
-
Save hengstchon/6ee65779f16496279394c782a18ed2b4 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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