Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Moving directories on Win32

by aplonis (Pilgrim)
on Nov 28, 2007 at 17:46 UTC ( [id://653604]=perlquestion: print w/replies, xml ) Need Help??

aplonis has asked for the wisdom of the Perl Monks concerning the following question:

Working on a script that lets user's have graphics files relocated just by droping a directory of them inside another directory.

So my script needs to move them out of there when done so it doesn't install them over again at next restart if users are lazy and leave them in side.

But this is on Win32 and I keep getting refused permission even though I'm running it as admin. I can create empty directories. I can create and rename files. But I cannot rename (move) directories.

Is there a workaround? or something I'm doing wrong?What I'd like to do is as below...

move( "C:/foo/bar/my_work/whatever", "C:/foo/bar/whatever");

Replies are listed 'Best First'.
Re: Moving directories on Win32
by wind (Priest) on Nov 28, 2007 at 17:55 UTC
    This works just fine for me:
    use File::Copy qw(move); use strict; move("C:/foo/bar/my_work/whatever", "C:/foo/bar/whatever") or die "Can +'t move: $!";
    What is your error message?

    - Miller

      The error message is..."Permission denied"...even though the move is going up one directory to my own desktop.

      I can manually make that same move, no problem. The script can mkdir to there, write a *.txt to there, just not move a directory there.

        Whenever you use a OS call and check for failure it is as well to display $^E as well (or instead of) $!. In this case, you would get the following:

        warn $!; Permission denied warn $^E The process cannot access the file because it is being used by another + process

        Which makes identifying the problem easier, if not the solution.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        Well, if you can mkdir the directory that you're trying to move to then I'm guessing you're most likely dealing with a locking issue for your source directory. Do you have window opened to that directory, or even a text editor with that directory as the last opened location?

        Try closing all extra programs and rerun the script. From outside the source directory of course. :)

        If all else fails, you could play around with File::Find to create your own 1 to 1 recursive move function. It would also probably fail at some point, but you would find the exact file or directory that is being locked that way.

        - Miller
Re: Moving directories on Win32
by jrsimmon (Hermit) on Nov 28, 2007 at 18:23 UTC
    Without seeing the code and the exact error, I can only guess...but the first guess is that your program is running from, has chdir'd to, or opened the directory you are trying to move.

      Here is the directory structure...

      C:/foo/bar/DESKTOP/SCRIPT_CWD/INNER/INNERMOST

      ...and the script residing in SCRIPT_CWD is trying to move INNERMOST out of INNER and into DESKTOP.

        Yes, but do you have a resource open in INNERMOST when you are attempting to do the move? If not, does DESKTOP have a resource that must be replaced but is in use?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://653604]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found