http://www.perlmonks.org?node_id=64973

thealienz1 has asked for the wisdom of the Perl Monks concerning the following question:

Okay now I am really peeved off... I have been working on this freaking script for the past two days... I though i had it, but no there is something wron with. And I knoW.... I KNOW... I have no idea what it is.

What I've been trying to do is copy a directory structure to a new directory and copy the files along. Now I have done this before with no troubles, but for some odd reason in this script alone the mkpath doesn't work.

#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 = <DBUSER>; 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 <file(s)> <group list> <file(s)> - can either specify a single file or directory NOTE: if not full path to file then assumes in current directory <group list> - 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"); } }

$ARGV[0] = a directory with no backslash and $ARGV[1] = a file to the directories I am to copy the "copy" directory to...

"The pajamas do not like to eat large carnivore toasters."
In German: "Die Pyjamas mögen nicht große Tiertoaster essen.
In Spanish: "Los pijamas no tienen gusto de comer las tostadoras grandes del carnívoro."