Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

perl copy files with condition

hi,

I am trying to copy files from one folder to another folder with in same server, I wrote the below perl script for that.
But I had a simple problem I want to copy files only with extension txt and pdf and not all the files but I know how to right script for one condition not for both can someone update my perl script so that it takes only files with txt and pdf extensions...

my script:
#!/usr/bin/perl

use strict;
use warnings;

my $source = "C:\\test";
my $destination = "C:\\test1";

opendir(DIR,"$source") or die "Cannot open $source\n";
my @files = readdir(DIR);
closedir(DIR);

foreach my $file (@files) {
  next if ($file !~ /\.txt$/i);
  system("copy \"$source\\$file\" \"$destination\"");
 
}
0
shragi
Asked:
shragi
1 Solution
 
ozoCommented:
next if ($file !~ /\.(txt|pdf)$/i);
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now