finddata has asked for the wisdom of the Perl Monks concerning the following question:
Expected one after renaminghtml `-- DCMS_DEMO |-- DCMS_DEMO.html |-- de_top | |-- Block_DV | | |-- Block_DV.html | | |-- rev1 | | | `-- rev1.html | | `-- rev2 | | `-- rev2.html | |-- CAD_checklist | | |-- CAD_checklist.html | | |-- rev1 | | | `-- rev1.html | | |-- rev2 | | | `-- rev2.html | | |-- rev3 | | | `-- rev3.html | | `-- rev4 | | `-- rev4.html | `-- de_top.html `-- new_block2 |-- ICC_L2_Checklist | |-- ICC_L2_Checklist.html | `-- rev1 | `-- rev1.html |-- checklist_tmp | |-- checklist_tmp.html | |-- rev1 | | `-- rev1.html | `-- rev2 | `-- rev2.html `-- new_block2.html
code which i tried:html `-- DCMS_DEMO |-- DCMS_DEMO.html |-- de_top | |-- Block_DV | | |-- Block_DV.html | | |-- rev1 | | | `--Block_DV_rev1.html | | `-- rev2 | | `-- Block_DV_rev2.html | |-- CAD_checklist | | |-- CAD_checklist.html | | |-- rev1 | | | `--CAD_checklist_rev1.html | | |-- rev2 | | | `-- CAD_checklist_rev2.html | | |-- rev3 | | | `--CAD_checklist_rev3.html | | `-- rev4 | | `--CAD_checklist_rev4.html | `-- de_top.html `-- new_block2 |-- ICC_L2_Checklist | |-- ICC_L2_Checklist.html | `-- rev1 | `--ICC_L2_checklist_rev1.html |-- checklist_tmp | |-- checklist_tmp.html | |-- rev1 | | `--checklist_tmp_rev1.html | `-- rev2 | `--checklist_tmprev2.html `-- new_block2.html
Error: The thing it affects all html files in all other directories. Example:sub runDir($$); sub runDir($$) { my $prefix = shift @_; # print $prefix,"\n"; my $dir = shift @_; #print "******$dir***","\n"; opendir(DIR, $dir) or die $!; my @entries = readdir(DIR); # print @entries,"\n"; close(DIR); foreach my $file (@entries) { next if ($file =~ /^\.+$/); if ( -d $dir . '/' . $file) { runDir($prefix . $file . '_', $dir . '/' . $file); } elsif ( ( -f $dir . '/' . $file ) && ( $file =~ /\.config$/ +) && ($file !~ /^$prefix/)) { my $suffix = $file; $suffix =~ s/^(\S+)-.+\.config$/$1.config/; rename $dir . '/' . $file, $dir . '/' . $prefix . $suffix +; } } } runDir('',$output_dir);
|-- DCMS_DEMO | |-- DCMS_DEMO_DCMS_DEMO.config | |-- DCMS_DEMO_DCMS_DEMO.html | |-- de_top | | |-- Block_DV | | | |-- DCMS_DEMO_de_top_Block_DV_Block_DV.config | | | |-- DCMS_DEMO_de_top_Block_DV_Block_DV.html | | | |-- rev1 | | | | |-- DCMS_DEMO_de_top_Block_DV_rev1_rev1.config | | | | `-- DCMS_DEMO_de_top_Block_DV_rev1_rev1.html | | | `-- rev2 | | | |-- DCMS_DEMO_de_top_Block_DV_rev2_rev2.config | | | `-- DCMS_DEMO_de_top_Block_DV_rev2_rev2.html | | |-- CAD_checklist | | | |-- DCMS_DEMO_de_top_CAD_checklist_CAD_checklist.config | | | |-- DCMS_DEMO_de_top_CAD_checklist_CAD_checklist.html | | | |-- rev1 | | | | |-- DCMS_DEMO_de_top_CAD_checklist_rev1_rev1.config | | | | `-- DCMS_DEMO_de_top_CAD_checklist_rev1_rev1.html | | | |-- rev2 | | | | |-- DCMS_DEMO_de_top_CAD_checklist_rev2_rev2.config | | | | `-- DCMS_DEMO_de_top_CAD_checklist_rev2_rev2.html | | | |-- rev3 | | | | |-- DCMS_DEMO_de_top_CAD_checklist_rev3_rev3.config | | | | `-- DCMS_DEMO_de_top_CAD_checklist_rev3_rev3.html | | | `-- rev4 | | | |-- DCMS_DEMO_de_top_CAD_checklist_rev4_rev4.config | | | `-- DCMS_DEMO_de_top_CAD_checklist_rev4_rev4.html | | |-- DCMS_DEMO_de_top_de_top.config | | |-- DCMS_DEMO_de_top_de_top.html | | `-- ICC_DPMHV_Checklist | `-- new_block2 | |-- CAD_checklist | |-- DCMS_DEMO_new_block2_new_block2.config | |-- DCMS_DEMO_new_block2_new_block2.html | |-- ICC_L2_Checklist | | |-- DCMS_DEMO_new_block2_ICC_L2_Checklist_ICC_L2_Checklist +.config | | |-- DCMS_DEMO_new_block2_ICC_L2_Checklist_ICC_L2_Checklist +.html | | `-- rev1 | | |-- DCMS_DEMO_new_block2_ICC_L2_Checklist_rev1_rev1.co +nfig | | `-- DCMS_DEMO_new_block2_ICC_L2_Checklist_rev1_rev1.ht +ml | `-- checklist_tmp | |-- DCMS_DEMO_new_block2_checklist_tmp_checklist_tmp.confi +g | |-- DCMS_DEMO_new_block2_checklist_tmp_checklist_tmp.html | |-- rev1 | | |-- DCMS_DEMO_new_block2_checklist_tmp_rev1_rev1.confi +g | | `-- DCMS_DEMO_new_block2_checklist_tmp_rev1_rev1.html | `-- rev2 | |-- DCMS_DEMO_new_block2_checklist_tmp_rev2_rev2.confi +g | `-- DCMS_DEMO_new_block2_checklist_tmp_rev2_rev2.html `-- html `-- DCMS_DEMO |-- DCMS_DEMO_DCMS_DEMO.html |-- de_top | |-- Block_DV | | |-- DCMS_DEMO_de_top_Block_DV_Block_DV.html | | |-- rev1 | | | `-- DCMS_DEMO_de_top_Block_DV_rev1_rev1.html | | `-- rev2 | | `-- DCMS_DEMO_de_top_Block_DV_rev2_rev2.html | |-- CAD_checklist | | |-- DCMS_DEMO_de_top_CAD_checklist_CAD_checklist.html | | |-- rev1 | | | `-- DCMS_DEMO_de_top_CAD_checklist_rev1_rev1.html | | |-- rev2 | | | `-- DCMS_DEMO_de_top_CAD_checklist_rev2_rev2.html | | |-- rev3 | | | `-- DCMS_DEMO_de_top_CAD_checklist_rev3_rev3.html | | `-- rev4 | | `-- DCMS_DEMO_de_top_CAD_checklist_rev4_rev4.html | `-- DCMS_DEMO_de_top_de_top.html `-- new_block2 |-- DCMS_DEMO_new_block2_new_block2.html |-- ICC_L2_Checklist | |-- DCMS_DEMO_new_block2_ICC_L2_Checklist_ICC_L2_Check +list.html | `-- rev1 | `-- DCMS_DEMO_new_block2_ICC_L2_Checklist_rev1_rev +1.html `-- checklist_tmp |-- DCMS_DEMO_new_block2_checklist_tmp_checklist_tmp.h +tml |-- rev1 | `-- DCMS_DEMO_new_block2_checklist_tmp_rev1_rev1.h +tml `-- rev2 `-- DCMS_DEMO_new_block2_checklist_tmp_rev2_rev2.h +tml
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to rename the file swiht its directory structure using perl?
by stevieb (Canon) on Mar 15, 2017 at 05:14 UTC | |
|
Re: How to rename the files its directory structure using perl?
by huck (Prior) on Mar 15, 2017 at 05:49 UTC | |
by finddata (Sexton) on Mar 15, 2017 at 06:12 UTC | |
by huck (Prior) on Mar 15, 2017 at 06:20 UTC | |
by huck (Prior) on Mar 15, 2017 at 06:26 UTC | |
by finddata (Sexton) on Mar 16, 2017 at 04:16 UTC | |
by huck (Prior) on Mar 16, 2017 at 05:03 UTC |