title: How can I add a prefix to all filenames under a directory?
body: <p>I am trying to prefix a string (<code>reference_</code>) to the names of all the *.bmp files in all the directories as well sub-directories. The first time we run the silk script, it will create directories as well subdirectories, and under each subdirectory it will store each mobile application's sceenshot with <code>.bmp</code> extension.</p>
  
  <p>When I run the automated silkscript for second time it will again create the *.bmp files in all the subdirectories. Before running the script for second time I want to prefix all the *.bmp with a string <code>reference_</code>.</p>
  
  <p>For example <code>first_screen.bmp</code> to <code>reference_first_screen.bmp</code>,
  I have the directory structure as below:</p>
  
  <pre><code>C:\Image_Repository\BG_Images\second
  ...
  C:\Image_Repository\BG_Images\sixth
  </code></pre>
  
  <p>having <code>first_screen.bmp</code> and <code>first_screen.bmp</code> files etc...</p>
  
  <p>Could any one help me out?</p>
  
  <p>How can I prefix all the image file names with <code>reference_</code> string?</p>
  
  <p>When I run the script for second time, the Perl script in silk will take both the images from the sub-directory and compare them both pixel by pixel.  I am trying with code below.
  Could you please guide me how can I proceed to complete this task.</p>
  
  <pre><code>#!/usr/bin/perl -w
  &amp;one;
  
  &amp;two;
  
  sub one {
  
      use Cwd;
  
      my $dir ="C:\\Image_Repository";
      #print "$dir\n";
      opendir(DIR,"+&lt;$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,"+&lt;$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,"+&lt;$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;
  }
  </code></pre>
  
  <p>I tried open call with '+&lt;' 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 actually it's not updating the files in the sub-directories.</p>