#!/usr/bin/perl use strict; use warnings; use File::Copy qw(copy); use File::Mirror qw(mirror recursive); use Try::Tiny; # return the last modified time sub get_mod_time { my $file = shift; my @stats = stat($file); my $mod = $stats[9]; return $mod; } # compare the two files' last modified times and return false or true sub same_mod_time { my ($src_file,$dst_file) = @_; my $same_mod = get_mod_time($src_file) != get_mod_time($dst_file) ? 0 : 1; return $same_mod; } local $\ = "\n"; if (-e "J:/") { while () { my ($source,$destination) = split(/\|/,$_); chomp($source,$destination); print "Copying $source to $destination"; # I guess at one time the copy failed and made the script die, so I added # Tiny::Try to keep the script from dying. try { if (-f $source) { copy($source,$destination) if same_mod_time($source,$destination) == 0; } elsif (-d $source) { # I had to change "mirror" to "recursive" to check for the same mod time. recursive { copy($_[0],$_[1]) if same_mod_time($_[0],$_[1]) == 0; } $source, $destination; } else { print "What did you do wrong?"; } } catch { print "Couldn't copy $source to $destination"; } } } else { print "Insert the thumb drive!"; } __DATA__ C:/Documents and Settings/me/My Documents/home/checkbook2.xls|J:/My Documents/home/checkbook2.xls C:/Documents and Settings/me/Local Settings/Application Data/Microsoft/Outlook/Outlook.pst|J:/application data/Outlook/Outlook.pst C:/Documents and Settings/me/My Documents/gaming|J:/My Documents/gaming C:/Documents and Settings/me/My Documents/fantasy|J:/My Documents/fantasy C:/Documents and Settings/me/Application Data/Notepad++/stylers.xml|J:/application data/Notepad++/stylers.xml C:/Documents and Settings/me/Application Data/HexChat|J:/application data/HexChat