in reply to move() error

Check the return status of the move function (I assume you are using File::Copy):
move($bookFiles[$h], $dir . "/Book Chapter/" . $bookName . "/" . $b +ookFileName[-1]) or warn $!;
Typical reasons are: the input file is not found or you do not have permissions to write to the directory or clobber an existing file.

From the File::Copy docs:

All functions return 1 on success, 0 on failure. $! will be set if an error was encountered.
You should also check the return status of the preceding mkdir.

Replies are listed 'Best First'.
Re^2: move() error
by JKasting (Novice) on Feb 26, 2010 at 18:25 UTC
    The error I'm getting says "No such file or directory" when I use the warning. However, I can verify that it does exist because I can find the file myself. I'm even printing out the old and new file paths when I run the script. It all seems to be correct. Suggestions?
      use strict and warnings and use lots of print's and file checks (-e):
      my @bookNameArray; my $bookName; my @bookFileName; for(my $h = 0; $h < scalar(@bookFiles); $h++){ @bookNameArray = split(/_/ , $bookFiles[$h]); @bookFileName = split("/" , $bookFiles[$h]); $bookName = $bookNameArray[-2]; my $newdir = $dir . "/Book Chapter/" . $bookName; print "newdir >>>$newdir<<<\n"; mkdir($newdir) or die "cant mkdir $newdir: $!"; my $src = $bookFiles[$h]; print "src>>>$src<<<\n"; my $dst = $dir . "/Book Chapter/" . $bookName . "/" . $bookFileName +[-1]); print "dst>>>$dst<<<\n"; if (-e $src) { print "$src exists\n"; } else { print "$src does not exist\n"; } # same -e check for dst move($src, $dst) or die "cant move : $!"; }
      See also Basic debugging checklist
        Ok, i've put all of those checks in. When it gets to the one that breaks the program, the "exists" check verifies that both the file and the directory exist. I've replaced all spaces with dashes as pileofrogs suggested, but that didn't help either. I'm really baffled here.
      Suggestions?

      Heed the error, its doesn't lie