Created
September 19, 2011 16:41
-
-
Save igniteflow/1226919 to your computer and use it in GitHub Desktop.
Python script to rename files in directory, transforming spaces to hyphens and the chars to lowercase
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
import os | |
""" | |
Renames the filenames within the same directory to be Unix friendly | |
(1) Changes spaces to hyphens | |
(2) Makes lowercase (not a Unix requirement, just looks better ;) | |
Usage: | |
python rename.py | |
""" | |
path = os.getcwd() | |
filenames = os.listdir(path) | |
for filename in filenames: | |
os.rename(filename, filename.replace(" ", "-").lower()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about removing leading space in multiple files in a directory?
i have many files in a directory and each one start with a space. so how to batch remove that?