http://www.perlmonks.org?node_id=733208


in reply to Re: How to prefix a string to all the files in a directories as well subdirectories
in thread How to prefix a string to all the files in a directories as well subdirectories

Hi leocharre, Thanks for your quick reply.
I am not intended to rename directories as well sub directories, all of these directories and subdirectories stores mobile application screen shot in .bmp files with name first_screen.bmp in all directoris. Only thing i want to prefix a string
"reference_" to all of these files recursively.Can u help me out how efficianlty i can prefix a string to all these files.Thanks in advance for your reply.

Replies are listed 'Best First'.
Re^3: How to prefix a string to all the files in a directories as well subdirectories
by cdarke (Prior) on Dec 30, 2008 at 10:53 UTC
    Like this:
    #!/usr/bin/perl use strict; use warnings; use File::Find; sub callback { my $file = $_; rename $file,"reference_$file" if -f $file } my $dir = 'C:/Image_Repository'; find (\&callback, $dir);
    Of course, there is always More Than One Way To Do It, so you can "hand craft" it if you enjoy lots of typing, but it probably won't be as efficient as using File::Find.