Created
November 6, 2018 06:17
-
-
Save sergixnet/23c95b0fd6873167afa6c5f4055498e8 to your computer and use it in GitHub Desktop.
Script to rename files of a folder
This file contains 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
# program to rename files with slug like names | |
import re | |
import os | |
import shutil | |
FOLDER_PATH = "/the-folder-path" | |
def slugify(fileName): | |
fileName = re.sub(r'\s|_', "-", fileName).lower() | |
return fileName | |
for fileName in os.listdir(FOLDER_PATH): | |
newfile = os.path.join(FOLDER_PATH, slugify(fileName)) | |
print(newfile) | |
shutil.move(os.path.join(FOLDER_PATH, fileName), newfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment