Skip to content

Instantly share code, notes, and snippets.

@alrafiabdullah
Created March 19, 2022 19:55
Show Gist options
  • Save alrafiabdullah/5e9d207e29ce5bd8b9d0a5ff7340c6af to your computer and use it in GitHub Desktop.
Save alrafiabdullah/5e9d207e29ce5bd8b9d0a5ff7340c6af to your computer and use it in GitHub Desktop.
Renames file names with specific instructions.
import os
FILE_LOC = "FILE_LOCATION"
# read all the file name from FILE_LOC
def read_file_name():
file_name = []
for file in os.listdir(FILE_LOC):
file_name.append(file)
return file_name
# rename all the file names in the directory with necessary changes
def rename_file_names(file_names_list):
for file_name in file_names_list:
temp = file_name.replace(" ", "_")
temp = temp.replace("@7x", "")
os.rename(FILE_LOC + "/" + file_name, FILE_LOC + "/" + temp)
if __name__ == "__main__":
rename_file_names(read_file_name())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment