Created
April 11, 2020 08:52
-
-
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 ) ?
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 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