简体   繁体   中英

File::Copy move directories accross drives in Windows not working?

I have a rather simple perl script that boils down to

use warnings; use strict;

use File::Copy;

#  ... some uninteressing things such as
#      assigning variables etc ...

move($dir_from, $dir_to) or die "could not move $dir_from to $dir_to";  

# ... more uninteresting things ...

This seems to work if $dir_1 and $dir_2 are on the same drive. But as soon as I try to move the directories accross drives, it won't work. Unfortunatly, I didn't find anything relating to that problem in the documentation of File::Copy . In fact, the documentation even states that

If possible, move() will simply rename the file. Otherwise, it copies the file to the new location and deletes the original.

Can someone confirm that my "problem" is indeed related to my assumption or is there another cause?

Actually, the File::Copy documentation does not state that it's able to move directories at all. The documentation just mentions files. Moving directories on the same partition "accidentally" works, because the rename() function (which is preferred over doing a copy+delete if source and destination are on the same partition) works for both files and directories.

BTW, the behavior is the same on Unix systems.

If you need a move which is working on directories, then look at CPAN modules like File::Copy::Recursive or File::NCopy .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM