I am trying to prefix a string (reference_)to all the *.bmp files in all the directories as well sub directories.

Correct me if I'm wrong, but you want to prefix the name of the files with "reference_", not the files themselves.

I tried open call with '+<' mode but i am getting compilation error for the read and write mode.

opendir(D,"+<$dir1") wouldn't result in a compilation error. It would result in a run-time error because it won't find the directory you named. "+" and "<" aren't even legal characters for directory names in Windows. readdir. You code has other problems, but I won't go into detail since I'm going to recommend that you use File::Find::Rule or similar.

use strict; use warnings; use File::Find::Rule qw( ); use Path::Class qw( file ); for ( File::Find::Rule->name( '*.bmp' ) ->file() ->in( $dir ); ) { my $file = file($_); my $o = $file; my $n = $file->dir()->file( 'reference_' . $file->basename() ); if (-e $n) { warn("$n already exists\n"); next; } if (!rename($o, $n)) { warn("Unable to rename $o: $!\n"); next; } }

In reply to Re: How to prefix a string to all the files in a directories as well subdirectories by ikegami
in thread 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.