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![]()

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![]()
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.

sorry should have stipulated.. im not running windows.
does the script need to look through a given directory? or will you just pass a filename to it?
is ruby allowed?

yeh preferably to traverse through a whole directory tree
Never used Ruby before, but I can install it no worries ...
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
Code:#! /usr/bin/python # Copyright 2008 Thura <thurahlaing06@gmail.com> # 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 <or> # 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 (24th September 2009)

That works great, cheers.
Its no big deal about the last 3 chars I guess..
Thanks again![]()

Modified to lowecase the last word.. which works perfectly..Code:#! /usr/bin/python # Copyright 2008 Thura <thurahlaing06@gmail.com> # 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 <or> # 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)
Thanks again.
There are currently 1 users browsing this thread. (0 members and 1 guests)