http://qs321.pair.com?node_id=763017


in reply to Re^2: Moving files and directories
in thread Moving files and directories

On win32 systems, stat often returns 0 for size when called for a directory. Some documentation suggests that it may sometimes return non-zero for directory size in some circumstances, but I haven't seen it myself. The '-s' file test is based on stat, so '-s' will often return 0 when used on a directory.

It might help you solve your problem if you check the return from the move function. See File::Copy for details. Maybe something like the following:

move( $source, $destination ) or die "move( $source, $destination ) fa +iled: $!";

The error message should help you understand why the move failed. On the other hand, testing I have done on Windows XP suggests that the error messages are not very good: in my tests it returned "No such file or directory" regardless of what the actual problem was. Also, while move worked for directories within a file system, copy didn't. Neither move nor copy worked for directories when moving or copying from one drive to another but move and copy both worked when moving or copying a file from one drive to another. So it seems that File::Copy is somewhat broken, at least for Active State perl 5.10.0 on Windows XP.

Replies are listed 'Best First'.
Re^4: Moving files and directories
by Anonymous Monk on May 09, 2009 at 08:33 UTC
    $!(errno) is equally as good on all platforms. On win32 you also get $^E.
Re^4: Moving files and directories
by Anonymous Monk on Mar 15, 2012 at 17:28 UTC

    I am having similar trouble with Windows. I resorted to using the back tick operator and window's move command to move directories...

    $s = "C:/temp/$here"; $d = "C:/$there/"; `move $s $d`; -e "$d/$here" && !-e $s ? print "Move successfully\n" : print "Move er +ror $d/$here \n".$!;