Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by jeffa (Bishop)
on Jul 07, 2002 at 03:25 UTC ( #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
Node Status?
node history
Node Type: note [id://179929]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2020-04-05 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (33 votes). Check out past polls.

    Notices?