Off topic:How to remove directories by identifying with its file name(i.e rev.config)?
0
0
Entering edit mode
7.1 years ago
finddata15 • 0

I wrote the following code to copy the files from one directory to another diorectory.Now i like to remove the some directories in the destination folder wherever the file(rev.config) includes.the folder which includes rev.config those folders should be removed using perl?Help me fix it

use File::Copy       qw( copy);
use File::Find::Rule qw( );
use File::Path       qw( make_path );
my $input_dir  = '/home/rpiasa/DMS_DEMO/project_space';
my $output_dir = '/home/rpiasa/output/project_space';

my %created;

for my $in (
   File::Find::Rule
   ->file()
   ->name(qr/^[^.].*\.config$/)
   ->in($input_dir)
) {
   my $match_file = substr($in, length($input_dir) + 1); 
   my ($match_dir) = $match_file =~ m{^(.*)/} ? $1 : '.';
   #print $match_dir,"\n";
   my $out_dir = $output_dir . '/' . $match_dir;
   my $out     = $output_dir . '/' . $match_file;
   make_path($out_dir) if !$created{$out_dir}++;
   copy($in, $out);

}
perl • 785 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2452 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6