Why does Perl File :: Copy appear without pauses?

I have a Perl script that runs on Windows XP. It uses the File :: Copy move function to move the directory tree to another location on the same drive. the script does not work (quietly) in Windows 2008. Nothing moves, nothing is deleted.

I am using ActiveState Perl 5.10.0 Build 1005 and the File :: Copy that comes with it.

Does anyone know about problems with ActiveState Perl in Windows 2008 that might cause this?

Sample script:

 use File::Copy; print "Move AAA to ZZZ\n"; move("AAA", "ZZZ"); print "Done.\n"; 
+4
source share
6 answers

In the documentation:

RETURN

All functions return 1 on success, 0 on failure. $! will be installed if an error occurs.

An example is impossible because it doesn’t check what $ is! is at failure. Try the following:

 move($from, $to) || die "Failed to move files: $!"; 
+12
source

If you do not want to check the return value, you can autodie do it for you.

Since move() and copy() return zero, indicating an error, and that autodie assumes that it is pretty straight forward.

 use strict; use warnings; use File::Copy; use autodie qw'copy move'; move("AAA", "ZZZ"); # no need to check for error, because of autodie print "Done.\n"; 

Assuming " AAA " does not exist, here is the output (on STDERR ).

  Can't move ('AAA', 'ZZZ'): No such file or directory at test.pl line 7
+8
source

I just ran into this myself, and in my specific situation, despite the same error ("There is no such file ..."), in fact I had a file from the depth of the hierarchy that I renamed, opened it in a text editor where something. As soon as I closed this file, an error occurred.

+2
source

I had strange things that happened to me on Windows with moving and deleting files. The solution was to use the CPAN File :: Remove module.

+1
source

Instead of scrolling through another half-dozen Perl modules looking for the one that did what I wanted, I took a hybrid approach and called DOS to use the move command. The DOS movement has its own characteristics. For example, if you copy c: \ temp \ AAA to c: \ temp \ BBB and BBB already exists, you get c: \ temp \ BBB \ AAA. But if the BBB does not exist yet, you get c: \ temp \ BBB, without AAA under it. To avoid this, I first create a BBB (if it does not exist) and then removes it. This leads to the creation of all directories before the BBB, if they are missing.

Here is my code:

 sub move($$) { my ($source, $target) = @_; if (! -d $source) { print " ERROR: Source directory does not exist: $source. Not copying to $target.\n"; } elsif (-d $target) { print " ERROR: Target directory already exists: $target. Not copying from $source.\n"; } else { $source =~ s|/|\\|g; $target =~ s|/|\\|g; my $results = `if not exist "$target" mkdir "$target" & rmdir "$target" & move /Y "$source" "$target"`; print " Results of move \"$source\" \"$target\":\n $results\n"; } } 
+1
source

I also found that move () and unlink () fail in files that were created in the last 10 seconds. I added a call to "sleep 10" before move (), and now it works! Strange, but true.

Then I found http://answers.microsoft.com/en-us/windows/forum/windows_7-files/windows-7-does-not-refresh-folder-views/9d1ede23-2666-4951-b3b9-b6c1ce3d1ebf?page = 23 which led me to add ...

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ LanmanWorkstation \ Parameters

 FileInfoCacheLifetime FileNotFoundCacheLifetime DirectoryCacheLifetime 

since DWORD is set to 0 ... and now it works without a pause. You cannot vouch for the potential impact of server performance.

This seems like crazy default behavior for me, and it's not limited to Perl!

Also see Windows file sharing: why sometimes created files do not appear for a period of time?

0
source

All Articles