Skip to content

Instantly share code, notes, and snippets.

@seungwoonlee
Last active January 16, 2019 10:28
Show Gist options
  • Save seungwoonlee/8bd48eab7c7a2d1721d197d410769e41 to your computer and use it in GitHub Desktop.
Save seungwoonlee/8bd48eab7c7a2d1721d197d410769e41 to your computer and use it in GitHub Desktop.
python file rename example
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