Solved

perl copy files with condition

Posted on 2014-10-06
1
321 Views
Last Modified: 2014-10-06
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
Comment
Question by:shragi
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40364543
next if ($file !~ /\.(txt|pdf)$/i);
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS: Making Pure CSS read more boxes thinner 5 41
BATCH to EXE Converter 2 40
PS call executable Files in Order 4 17
IDE for Python 5 27
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question