in reply to Optimize file renaming.
Update:chdir("e:\\perl\\comics\\"); foreach my $fname (glob("*.png")) { my $append = "0" x (7 - length($fname)); rename($fname, $append.$fname) or die "Cannot rename $fname"; }
in all honesty, for my usage I'd have written
from the appropriate directoryperl -e 'rename($_,("0"x(7-length($_))).$_) for glob("*.png")'
But it's probably best to maintain some readability when messing around with the filesystem
Update2:
rename($_,substr("000$_",-7)) is even groovier ( borrowed from EdwardG ), although it'll mess you up, if there are longer names, while the previous version won't
|
|---|