Page 1 of 2

File renaming utility

Posted: Thu May 24, 2007 5:44 pm
by Luke
Anybody know of a good free utility that allows you to rename files in your file system based on regular expressions? Thanks!

Posted: Thu May 24, 2007 5:59 pm
by RobertGonzalez
What OS?

Posted: Thu May 24, 2007 6:05 pm
by Jenk
bash/csh/ksh/tsh/sh + tr + mv

Posted: Thu May 24, 2007 6:12 pm
by Luke
sorry I should have mentioned that. Windows XP

Posted: Thu May 24, 2007 7:11 pm
by alex.barylski
Many moons ago I wrote a small utility to do do just that, then I searched for something similar before I posted to my then favourite site and found this:

http://www.codeproject.com/shell/shswapl.asp

You may also might might to have a look around here:

http://www.shellcity.net/

Cheers :)

Posted: Thu May 24, 2007 8:53 pm
by Arawn
THE Rename

It's been a while since I used it but make sure you choose the type of Regexp (Perl/Posix) you want in the Preferences for best results.

Posted: Thu May 24, 2007 8:55 pm
by Kieran Huggins
I had shswap installed back in my win2k days and I loved it in unnatural ways. Unfortunately, since upgrading to XP I've never been able to get it to work :-(

Instead I've used a decidedly less convenient vbs script which I can post if you're interested, and will try http://www.12noon.com when I get a chance.

Posted: Thu May 24, 2007 10:44 pm
by alex.barylski
Hmmm...didn't spot the lack of XP support. Is this using the tool directly or compiling from scratch?

You should let the author know, maybe he'll update it to work on XP :)

Posted: Fri May 25, 2007 12:49 am
by Chris Corbyn
I imagine if you had cygwin installed you'd be able to take comfort in a linux environment for things like this.

Code: Select all

for x in $(find /in/this/path -regex .*/matching/this/pattern)
do
  #something involving mv command with full path $x
done

Posted: Fri May 25, 2007 1:19 am
by Luke
I think I'll give that a try. I've been meaning to anyway. Thanks Chris :)

Posted: Fri May 25, 2007 2:21 am
by vigge89

Posted: Fri May 25, 2007 1:05 pm
by Luke
How come it tells me "rename: command not found" in cygwin? That seems like the perfect command... ? :(

Posted: Fri May 25, 2007 1:18 pm
by Chris Corbyn
The Ninja Space Goat wrote:How come it tells me "rename: command not found" in cygwin? That seems like the perfect command... ? :(
The command is mv, not rename. mv means move. Move file foo to file bar. Or move file olddir/foo to newdir/foo :)

EDIT | Lets say I wanted to change all .php files to .phps in my current working directory " . ".

Code: Select all

for x in $(find . -name '*.php')
do
  mv $x ${x}s
done

Posted: Fri May 25, 2007 1:24 pm
by Luke
isn't there a rename command though?

hmm... how would you use a part captured with parenthesis in the new name? I tried this:

Code: Select all

$ for x in $(find /cygdrive/c/htdocs/test -regex '/cygdrive/c/htdocs/test/([0-9
]+)[^\.]+\.txtt')
> do
>   mv $x $1.txt
> done
it didn't work :(

Posted: Fri May 25, 2007 1:33 pm
by Chris Corbyn
The Ninja Space Goat wrote:isn't there a rename command though?
Nope, mv is the rename command. There's no need for a rename command when mv does just that. Think of it this way. Moving a file from foo/bar to zip/bar isn't just "moving" a file. You renamed the full path, which results in the file being moved. The opposite is true. If you rename one.php to two.php you just moved it really. If you want a rename command, type this when you open cygwin:

Code: Select all

alias rename=mv
;)