Moving Directory using win32api::File

Discussion in 'Perl Misc' started by Brian, Apr 21, 2004.

  1. Brian

    Brian Guest

    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
    Brian, Apr 21, 2004
    #1
    1. Advertising

  2. Brian

    Sisyphus Guest

    Brian wrote:
    > 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

    --
    To reply by email u have to take out the u in kalinaubears.
    Sisyphus, Apr 22, 2004
    #2
    1. Advertising

  3. Brian

    Brian Guest

    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.

    Sisyphus wrote:

    > Brian wrote:
    > > 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
    >
    > --
    > To reply by email u have to take out the u in kalinaubears.
    Brian, Apr 22, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. linkswanted
    Replies:
    0
    Views:
    672
    linkswanted
    Dec 21, 2007
  2. linkswanted
    Replies:
    0
    Views:
    1,535
    linkswanted
    Jan 6, 2008
  3. linkswanted
    Replies:
    0
    Views:
    435
    linkswanted
    Jan 23, 2008
  4. linkswanted
    Replies:
    0
    Views:
    619
    linkswanted
    Jan 24, 2008
  5. Tom Robinson
    Replies:
    2
    Views:
    485
    Tom Robinson
    Jul 13, 2004
Loading...

Share This Page