#Module use to recurse files in directory use File::Find; #Module used to copy files use File::Copy; #Module to copy directory structure use File::Path; if(defined($ARGV[0]) && defined($ARGV[1])) { $ARGV[0] =~ s/\\/\//g; $ARGV[1] =~ s/\\/\//g; print "$ARGV[0]\n\n"; #open data for user file open(DBUSER,"$ARGV[1]") || die "Cannot open user : $!"; my @Directory_Of_Users = ; close(DBUSER); foreach $Single_User_Directory (@Directory_Of_Users) { chomp($Single_User_Directory); $Single_User_Directory =~ s/\\/\//g; if(-f "$ARGV[0]") { #If its just a file print "Copying file to $Single_User_Directory - "; copy("$ARGV[0]","$Single_User_Directory"); print "Successful\n"; } elsif(-d "$ARGV[0]") { print "Copying path to $Single_User_Directory - "; mkpath([$ARGV[0], $Single_User_Directory], 1, 0711); print "Successful\n"; find(\&each_file,"$ARGV[0]//"); } else{ die "You Suck JT Archie - there's your motivation..."; } } } else{ print qq~ Usage: perl sendfile.pl - can either specify a single file or directory NOTE: if not full path to file then assumes in current directory - text file of directories to send to NOTE: if not full path assumes in current directory ~; } sub each_file{ my $filename = $_; my $filepath = $File::Find::name; if(-f "$filepath") { my $copypath = $filepath; $copypath =~ s/$ARGV[0]/$Single_User_Directory/i; copy("$filepath","$copypath"); } }