Hi Monks,

I am trying to prefix a string (reference_)to all the *.bmp files in all the directories as well sub directories. At first time when we run silk script it will creates directries as well subdirectries,under each subdirectories it will stores each mobile application's sceenshot with .bmp extension.
.when i run the automated silkscript for second time it will again creates *.bmp files in all the subdirectories.Before running the script for second time i want to prefix all the *.bmp with a string reference_.
For Example first_screen.bmp to reference_first_screen.bmp
I have the directory structure as below
Image C:\Image_Repository\BG_Images\second and C:\Image_Repository\BG_Images\sixth having first_screen.bmp and first_screen.bmp files etc...,could any one help me out how can i prefix all the imagefiles with "reference_" string
.When i run the script for second time perl script in silk will take both the images from the subdirectory and compairs the both pixel by pixel.I am trying with below code, could u please guide me how can i proceed to complete this task.
#!/usr/bin/perl -w &one; &two; sub one { use Cwd; my $dir ="C:\\Image_Repository"; #print "$dir\n"; opendir(DIR,"+<$dir") or "die $!\n"; my @dir = readdir DIR; #$lines=@dir; delete $dir[-1]; print "$lines\n"; foreach my $item (@dir) { print "$item\n"; } closedir DIR; } sub two { use Cwd; my $dir1 ="C:\\Image_Repository\\BG_Images"; #print "$dir1\n"; opendir(D,"+<$dir1") or "die $!\n"; my @dire = readdir D; #$lines=@dire; delete $dire[-1]; #print "$lines\n"; foreach my $item (@dire) { #print "$item\n"; $dir2="C:\\Image_Repository\\BG_Images\\$item"; print $dir2; opendir(D1,"+<$dir2") or die " $!\n"; my @files=readdir D1; #print "@files\n"; foreach $one (@files) { $one="reference_".$one; print "$one\n"; #rename $one,Reference_.$one; } } closedir DIR; }
I tried open call with '+<' mode but i am getting compilation error for the read and write mode.
When i am running this code it shows the files in BG_images folder with prefixed string but actully its not updating files in the subdirectories.

In reply to How to prefix a string to all the files in a directories as well subdirectories by perladdict

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.