Moving Directory using win32api::File

B

Brian

I am trying to move a directory that contains numerous other
subdirectories, e.g. c:\temp\source\temp1, temp2, to a new directory,
e.d. c:\test. Here is my script:

use Win32API::File qw( :ALL );
use strict;

my $source = "c:\\temp\\source";
my $destination = "c:\\test";
my $mvError = "";

MoveFileEx( $source, $destination, MOVEFILE_REPLACE_EXISTING() )
or die "Can't move $source to $destination: ",fileLastError(),"\n";

I get the following error:

Can't move c:\temp\source to c:\test\: Access is denied

Any ideas?

When I try: MoveFile( $source, $destination )

I get an error stating that the file already exists
 
S

Sisyphus

Brian said:
I am trying to move a directory that contains numerous other
subdirectories, e.g. c:\temp\source\temp1, temp2, to a new directory,
e.d. c:\test. Here is my script:

use Win32API::File qw( :ALL );
use strict;

my $source = "c:\\temp\\source";
my $destination = "c:\\test";
my $mvError = "";

MoveFileEx( $source, $destination, MOVEFILE_REPLACE_EXISTING() )
or die "Can't move $source to $destination: ",fileLastError(),"\n";

I get the following error:

Can't move c:\temp\source to c:\test\: Access is denied

Any ideas?

When I try: MoveFile( $source, $destination )

I get an error stating that the file already exists

Just a guess:
You need administrator rights to delete files from C:\temp (which would
not be unusual if that is your $ENV{'TEMP'} directory) - which is why
you get the "Access is denied" message. Creating a copy, however, poses
no problem - so that part of MoveFileEx() succeeds.
I assume that the "file already exists" message (that you subsequently
get) is, in fact, correct ?

Cheers,
Rob
 
B

Brian

Nope that is not it. I am logged on as administrator. As well, nothing
succeeds, there is no copy, nothing exists in destination directory. I
just think MoveFile displays a different error than MoveFileEx does for the
same condition.

I would be grateful for any other ideas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top