Forum Moderators: coopster & phranque

Message Too Old, No Replies

Renaming Files With Perl

How to rename multiple files with Perl.

         

maccas

6:12 am on May 27, 2003 (gmt 0)

10+ Year Member



Can anyone help me or point me in the right direction? I have about 400 txt files numerically named 1.txt to 400.txt and I want to rename them all to product names 1.txt becomes bigbluewidgets.txt etc.

Robber

9:51 am on May 27, 2003 (gmt 0)

10+ Year Member



You should find the rename() function can do this. Have a look in the documentation for the exact syntax, but I think you just give the old name and the new name and thats about it, so just stick it in a loop and you're done.

BCMG_Scott

1:29 pm on May 28, 2003 (gmt 0)

10+ Year Member



What OS? If you are in Linux there may be a command line function called rename (man rename to check) The format is:

rename [from] [to] [files]

So if you wanted to rename all .txt files to .html you would do: rename .txt .html *.txt

You can also use perl command line (can't find the exact code, but this will create a "backup" of the file:

perl -p -i.html *.txt

only problem is that it would name it file1.txt.html, I used to have a command line code to do this, can't find it now.

if you are using Windows, rename from DOS/Command Prompt (rename /? for more info).

Scott Geiger