Hi,

I wrote a script which copies files in directory to an another
directory based on user input. Any suggestions to simplify or shorten
this? I'm using Win XP.

-L

--------------------code -------------------------

#!/bin/perl

use warnings;
use strict;
use File::Copy;

my $dire;
my $destination;
my $days;

#Dir from where to copy
while (1){
  print "\nPath to dir for files to copy: ";
  chomp($dire = <STDIN>);
  #Check dir
  if ($dire !~ /^.+\/+$/){
    print "\nGive dir like C:/Temp/\n";
    next;
  }
  last;
}

#Dir to copy
while (1){
  print "\nPath to copy: ";
  chomp($destination = <STDIN>);
  #Check dir
  if ($destination !~ /^.+\/+$/){
    print "\nGive dir like C:/Temp/\n";
    next;
  }
  last;
}

#Days from this day to copy
while (1){
  print "\nPlease enter days from current date of modified files: ";
  chomp($days = <>);
  # Check for non-numeric characters
  if ($days =~ /\D/){
    print "\nPlease enter a number";
    next;
  }
  last;
}

print "\nCopied files:\n\n";

opendir DIR, $dire;
foreach my $filename (readdir(DIR)) {
       next if -d $filename;
       next if -f $filename and -M $filename > $days;
       print "$filename \n";
       copy($filename, $destination) or die "Couldn't copy: $!";
}

-------------------- end -------------------------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to