Last active
January 16, 2019 10:28
-
-
Save seungwoonlee/8bd48eab7c7a2d1721d197d410769e41 to your computer and use it in GitHub Desktop.
python file rename example
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 | |
def rename_movie_file(path, check_str): | |
for filename in os.listdir(path): | |
file_name, file_ext = os.path.splitext(filename) | |
file_ext = file_ext.lower() | |
if file_ext == '.md': | |
if check_str in filename: | |
file_name = file_name.replace(check_str, "") | |
rename_filename = file_name + file_ext | |
full_filename = os.path.join(path, filename) | |
full_rename_filename = os.path.join(path, rename_filename) | |
os.rename(full_filename, full_rename_filename) | |
print('Renamed : ', full_filename, ' -> ', full_rename_filename) | |
if __name__ == '__main__': | |
#path = r"C:\Users\admin\python\rename-test" | |
path = os.getcwd() | |
check_str = "python-" | |
print(path) | |
rename_movie_file(path, check_str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment