Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 11, 2020 08:52
Show Gist options
  • Save openroomxyz/06a5ae32a52e8dbb64a229d73d6731da to your computer and use it in GitHub Desktop.
Save openroomxyz/06a5ae32a52e8dbb64a229d73d6731da to your computer and use it in GitHub Desktop.
Python : How do i rename all files in folder so that they get UUID name (renaming all files in folder ) ?
import uuid
import os
def get_extension(name):
return name.split('.')[-1]
def get_list_of_files_only_in_folder(folder_path):
return [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))] #
def rename_all_files_inside_folder(folder_path):
onlyfiles = get_list_of_files_only_in_folder(folder_path)
path_fileName_newFileName = [(mypath, i, str(uuid.uuid4()) +"." + get_extension(i)) for i in onlyfiles]
for path, old_name, new_name in path_fileName_newFileName:
os.rename(path + "\\"+ old_name, path + "\\"+ new_name)
rename_all_files_inside_folder("C:\\Users\\cosmos\\Desktop\\pix2pix_deep_learning")
#print(path_fileName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment