File renaming utility

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

File renaming utility

Post by Luke »

Anybody know of a good free utility that allows you to rename files in your file system based on regular expressions? Thanks!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What OS?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

bash/csh/ksh/tsh/sh + tr + mv
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

sorry I should have mentioned that. Windows XP
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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 :)
Arawn
Forum Commoner
Posts: 42
Joined: Sat May 05, 2007 6:03 am

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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 :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I think I'll give that a try. I've been meaning to anyway. Thanks Chris :)
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

How come it tells me "rename: command not found" in cygwin? That seems like the perfect command... ? :(
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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 :(
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
;)
Post Reply