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