Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

(jeffa) Re: how to rename all files in a dir

by jeffa (Bishop)
on Jul 07, 2002 at 03:25 UTC ( [id://179929]=note: print w/replies, xml ) Need Help??


in reply to how to rename all files in a dir

These things i tend to do with quick one-liners. Say you want to prepend the number to all .txt files:
perl -e 'while(<*.txt>){$n=sprintf("%02d%s",++$i,$_);rename$_,$n}'

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
(zdog) Re: (2) how to rename all files in a dir
by zdog (Priest) on Jul 07, 2002 at 15:49 UTC
    In case there is no specified file extension like .txt, something like this can be done:

    perl -e 'for (grep {-f} <*>) { rename $_, sprintf("%02d%s", ++$i, $_) }'

    Zenon Zabinski | zdog | zdog@perlmonk.org

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://179929]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 14:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found