Fuisms has asked for the wisdom of the Perl Monks concerning the following question:
use Class::Date qw(:errors date localdate gmdate now); # Check system date for filename $date = localdate(time); $date->monname; $date->yr; $month = substr($date->monname,0,3); $file_name = $month . $date->yr . "BU"; # Opens log to write to open (MYFILE, '>>c:\\Perl scripts\\TEST1.log'); # Opens source directory and compares all files to all the files - If + new files, it copies it to 2nd location opendir (DIR1, "C:\\TEST1") or die print MYFILE "Today is $date \n Cou +ldn't open directory, C:\\TEST1"; while ($file1 = readdir DIR1) { #print "$file1 \n"; push(@files1, $file1); } #print "@files1 \n"; closedir DIR1; #opendir (DIR2, "C:\\TEST2") or die print MYFILE "Today is $date \n Co +uldn't open directory, C:\\TEST2"; while ($file2 = readdir DIR2) { #print "$file2 \n"; push(@files2, $file2); } #print "@files2 \n"; closedir DIR2; #Compares the directories and copies the missing files to the other di +rectory %temp = map {$_,$_} @files2; for(@files1) { next if exists $temp{$_}; system("copy C:\\TEST1\\$_ C:\\TEST2\\"); print MYFILE "$_ has been copied\n"; } close(MYFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing Directories and copy files
by toolic (Bishop) on Jul 27, 2010 at 21:34 UTC | |
by Fuisms (Initiate) on Jul 27, 2010 at 21:56 UTC | |
by toolic (Bishop) on Jul 27, 2010 at 22:29 UTC | |
by Fuisms (Initiate) on Jul 27, 2010 at 22:41 UTC | |
|
Re: Comparing Directories and copy files
by dasgar (Priest) on Jul 27, 2010 at 23:34 UTC | |
|
Re: Comparing Directories and copy files
by NiJo (Friar) on Jul 28, 2010 at 17:59 UTC |