The following code will rename the directories and sub directories names as per the text file (i.e mapfile.txt) mapfile.txt:
PROJECT:DCMS_DEMO:prj1 BLOCK:de_top:blk1 BLOCK:new_block2:blk2 BLOCK:test:blk3 CHECKLIST:Block_DV:checklist1 CHECKLIST:Block_Physical_design_checklist:checklist2 CHECKLIST:CAD_checklist:checklist3 CHECKLIST:DFT:checklist4
Code which i used to rename folders and sub folders as per text file:
##READ THE TEXT FILE AND RENAME THE DIRECTORIES #### my $dir_map = read_map($mapfile); my $top_dir=$output_dir; rename_dirs( $top_dir, $dir_map ); sub rename_dirs { my ( $top_dir, $dir_map ) = @_; opendir (my $dh, $top_dir) or die "Can't open $top_dir: $!"; my $save_dir = getcwd(); chdir $top_dir; while (my $dir = readdir $dh) { #print $dir,"\n"; next if ($dir eq '.') or ($dir eq '..'); if ( exists $dir_map->{$dir} ) { my $new_name = $dir_map->{$dir}; File::Copy::move( $dir, $new_name ) or die "Could not rename '$dir' as '$new_name': $!"; $dir = $new_name; } rename_dirs( $dir, $dir_map ) if -d $dir; } chdir $save_dir; } ##SUB ROUTINE TO READ THE TEXT FILE FROM COMMAND LINE ARGUMENTS## sub read_map { my ( $fn ) = @_; my %dir_map; open( my $fh, '<', $fn ) or die "Could not open file '$fn': $!"; while( my $line = <$fh> ) { chomp $line; my @fields = split /:/, $line; if ( @fields == 3 ) { $dir_map{$fields[2]} = $fields[1]; } } close $fh; return \%dir_map; }
My output obtained from above code:
DCMS_DEMO |-- DCMS_DEMO.config |-- DCMS_DEMO.html |-- de_top | |-- Block_DV | | |-- Block_DV.config | | |-- Block_DV.html | | |-- rev1 | | | |-- rev1.config | | | `-- rev1.html | | `-- rev2 | | |-- rev2.config | | `-- rev2.html | |-- CAD_checklist | | |-- CAD_checklist.config | | |-- CAD_checklist.html | | |-- rev1 | | | |-- rev1.config | | | `-- rev1.html
My query explanation: Likewise i should do for all .config file contents inside the file.And i should not consider the last level directory structure for doing the same process?(i.e rev.*) cat DCMS_DEMO.config
blk3 : 0% : 0% blk1 : 0.68% : 0.99% blk2 : 0.00% : 0.00% OVERALL_STATUS=0.23% PARTIAL_STATUS=0.33%
Expected output:
test : 0% : 0% de_top : 0.68% : 0.99% new_block2 : 0.00% : 0.00% OVERALL_STATUS=0.23% PARTIAL_STATUS=0.33%

In reply to How to match the file and rename the contents in the .config files of directories and subdirectories using perl? by finddata

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.