Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-15-2006, 03:40 PM   #16
Registered: Oct 2004
Posts: 215

Rep: Reputation: 30

There are probably much better ways to do it, but I'm glad I could help.
Old 10-30-2012, 07:52 PM   #17
LQ Newbie
Registered: Oct 2012
Posts: 1

Rep: Reputation: Disabled
Just what I was looking for!

Thanks for posting the awesome script -- it's exactly what I was looking for!

Originally Posted by bushidozen View Post
I just looked over your code, and I saw a couple of errors, so I rewrote it a little:

# Replace upper case with lower case
# Replace spaces with underscores

import os, sys
if len(sys.argv) == 1:
    filenames = os.listdir(os.curdir)
    filenames = sys.argv[1:]
for filename in filenames:
    newfilename = filename.lower()
    if ' ' in newfilename:
        newfilename = newfilename.replace(' ', '_')
        print "Renaming", filename, "to", newfilename, "..."
    os.rename(filename, newfilename)
This code will attempt to convert all filenames to lowercase (even those that are already lowercase), which could translate into a lot of wasted cycles (ie. if all of the files in the directory are already lowercase), but it actually runs faster than trying to determine its case as in the previous code (by using the if statement). Enjoy.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mount DVD While Preserve Upper Case File Names xptools Linux - Software 2 12-12-2005 11:18 AM
Why are all my upper case files being shown as lower case?? [Kernel 2.6.9-1.667 FC3] t3gah Fedora 4 03-11-2005 05:09 PM
remove * from file nameS zchoyt Linux - Newbie 1 02-13-2005 05:33 PM
Lower case to upper case letter sudhasmyle Programming 1 12-03-2004 05:15 AM
chaging directory names to lower case andy753421 Linux - General 2 05-11-2004 03:12 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration