-
-
Save igniteflow/1226919 to your computer and use it in GitHub Desktop.
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()) |
works great exactly what i needed
Thanks :) works great for me.
Thanks..! it worked for me. Though my requirement is bit different.
Thank you for sharing. Very useful "as is" and a useful little script for learning :)
I have two cameras in the raspberry pie that every time it overwrites the name of the image, for example, image 1 and image 2,
when I run it again, it overwrites on image 1 and image 2, how can I rename previous images to avoid overwriting?
Thank you
Thank you so much,,, I searched so many links to rename my files in a folder with a regular expression/pattern none worked, But this.
Is there any way to extend this script down the tree to rename folders and files within folders???
Thank you, that's what i was looking for.
Does it read the names in ascending order?
Great! It’s simple, it works. 👍 Thank you!
There's a simpler way to do this using the linux rename
command, if you'd like:
rename --force 's/ /-/g' *
If you run that on the CLI it'll rename all files in the current directory -- exchanging spaces for dashes.
@rdegges that does not make uppercase -> lowercase though.
how can i change only the first letter of a filename into uppercase??
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?
@Hellstorm90 use os.path.isfile to check if file (or os.path.isdir to check if directory)