RabbieBurns Posted September 24, 2009 Posted September 24, 2009 Just wondering if someone could knock us up a simple script, bash, or perl, or python, or whatever is easiest.. basically just looking to try to change this.is.the.filename.ext to This.Is.The.Filename.ext Thanks in advance
andy_b Posted September 24, 2009 Posted September 24, 2009 Not a script, but this may help - Renamer is quite useful for file renaming. You can add a case rule to captialise every word which should do what you require.
RabbieBurns Posted September 24, 2009 Author Posted September 24, 2009 sorry should have stipulated.. im not running windows.
Arcath Posted September 24, 2009 Posted September 24, 2009 does the script need to look through a given directory? or will you just pass a filename to it? is ruby allowed?
RabbieBurns Posted September 24, 2009 Author Posted September 24, 2009 yeh preferably to traverse through a whole directory tree Never used Ruby before, but I can install it no worries ...
Guest monkeyx Posted September 24, 2009 Posted September 24, 2009 Here is a pyhton script that I use where I use the string.title() function to do what you are asking for. It does also captize the extension, but sure you could work out how set the last 3 chars to lowercase #! /usr/bin/python # Copyright 2008 Thura # Just a small script to rename files and folders in nautilus recursively # Tested under Ubuntu 8.04, should work fine with other Linux dist ... import os,sys,string dirs = [] def ren(path): oldname = os.path.split(path)[1] newname = oldname.title() print 'Renaming ' + oldname + ' to ' + newname; #Change this line for your preferred filename ... #For example, newname = oldname.lower() # newname = "Your Prefix" + oldname # newname = oldname + "Your suffix" newpath = os.path.join(os.path.split(path)[0],newname) os.rename(path,newpath) if os.path.isdir(newpath): for name in os.listdir(newpath): ren(os.path.join(newpath,name)) for i in sys.argv[1:]: dirs.append(i) for dir in dirs: ren(dir)
RabbieBurns Posted September 24, 2009 Author Posted September 24, 2009 That works great, cheers. Its no big deal about the last 3 chars I guess.. Thanks again
RabbieBurns Posted September 24, 2009 Author Posted September 24, 2009 #! /usr/bin/python # Copyright 2008 Thura # Just a small script to rename files and folders in nautilus recursively # Tested under Ubuntu 8.04, should work fine with other Linux dist ... import os,sys,string dirs = [] def ren(path): oldname = os.path.split(path)[1] newname = oldname.title() temp = newname.split(".") temp[-1] = temp[-1].lower() newname = ".".join(temp) print 'Renaming ' + oldname + ' to ' + newname; #Change this line for your preferred filename ... #For example, newname = oldname.lower() # newname = "Your Prefix" + oldname # newname = oldname + "Your suffix" newpath = os.path.join(os.path.split(path)[0],newname) os.rename(path,newpath) if os.path.isdir(newpath): for name in os.listdir(newpath): ren(os.path.join(newpath,name)) for i in sys.argv[1:]: dirs.append(i) for dir in dirs: ren(dir) Modified to lowecase the last word.. which works perfectly.. Thanks again.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now