LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 07-15-2006, 02:40 PM   #16
bushidozen
Member
 
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, 06:52 PM   #17
webdevguy
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!

Quote:
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:
Code:
#!/usr/bin/python

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

import os, sys
if len(sys.argv) == 1:
    filenames = os.listdir(os.curdir)
else:
    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.
 
  


Reply


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 10: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 04:09 PM
remove * from file nameS zchoyt Linux - Newbie 1 02-13-2005 04:33 PM
Lower case to upper case letter sudhasmyle Programming 1 12-03-2004 04:15 AM
chaging directory names to lower case andy753421 Linux - General 2 05-11-2004 02:12 PM


All times are GMT -5. The time now is 03:58 AM.

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