Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: rmtree deletes everything inside the folder but doesn't deletes the root folder him self

by mce (Curate)
on Apr 28, 2004 at 08:57 UTC ( #348759=note: print w/replies, xml ) Need Help??

in reply to rmtree deletes everything inside the folder but doesn't deletes the root folder him self


Just a small remark, but the script is't executed from within the directory you are trying to move, is it?

The permission denied means -most likely- that there is a lock on this directory. So some process is running from within this directory.

Dr. Mark Ceulemans
Senior Consultant
BMC, Belgium
  • Comment on Re: rmtree deletes everything inside the folder but doesn't deletes the root folder him self

Replies are listed 'Best First'.
Re: Re: rmtree deletes everything inside the folder but doesn't deletes the root folder him self
by Nelly (Novice) on Apr 28, 2004 at 09:01 UTC
    Ofcourse, the script isn't running from the directory I'm trying to move.
    But, How can I unlock this directory? chmod didn't helped me.

      This sounds like the classic "in-use" problem. Even if the process doing the deletion doesn't have the directory to be deleted as one of it current directories-- every process has a current directory for each logical drive visible to it!--if any other process in the system is using that directory, directly or indirectly, then permission to delete that directory will be denied.

      As a simple example: Say you have a system with 2 drive C: & D:, the directory your trying to delete is d:\foo. You have a shell window running, and at some point you switch to the d: drive and cd to \foo....then you switch back to the c: to run the script to delete d:\foo. You get permission denied.

      Even though you are running the script at the C:\perl prompt, that shell session still has a handle to d:\foo, and so the system won't let you delete it. Right or wrong, that is the way the system works, and you have to work within that constraint.

      The one that usually catches me out is when I have edited a file in the target directory tree and even though I have closed the file, the file dialog retains the last directory I visited as the default location for the next time I want to open a file. So, even though I have no file open in that directory, the file dialog retains a handle to it, and I am prevented from deleting it until I either close the editor, or bring up the file dialog and switch to a different directory.

      The really horrible bit is that there are many file dialogs in the system, and each retains it's own sense of the CWD. It can be a real pain working out what and where the open handle is being retained.

      I'm sorry, but I don't have a solution to this, just a logical (if neither official nor what you want to hear) explanantion.

      The explorer seems to have some special logic built in so that if you right-click delete a subtree, the root directory of that subtree, which you made a CWD when you highlighted it, doesn't disappear until you move to another location, and it then is deleted. Something similar to the unix "mark for deletion" process. Unfortunately, this seems to a be a property of the explorer, rather than the underlying OS, and worse, even the explorer doesn't seem to be able to get it right all the time.

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      Check the permissions on the directory the one you wish to move is in. Also, if you are on an OS that uses it, check the extended error $^E
Re^2: rmtree deletes everything inside the folder but doesn't deletes the root folder him self
by Anonymous Monk on Oct 15, 2011 at 00:12 UTC
    You need to select the "no_chdir" option so it doesn't change to the directory you're acting on: find({ wanted => \&process, no_chdir => 1 }, '.');

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://348759]
[choroba]: Tire chains are mandatory here in mountains, and the only unprepared each year are gritters
[stevieb]: I have a 3 day winter survival kit in my vehicle in the event I get snowed in in the mountains (which has happened before due to avalanches closing the roads (and once in the summer due to a massive forest fire that trapped us
[perldigious]: a handful of people in my work area did not make it, but I live pretty close and it's flat the whole way, so I didn't have any trouble. The roundabout is the worst thing I have to negotiate.
[thezip]: G'day all!
[perldigious]: Well, that and dodging the people who forget how ice works right away. :-)
[stevieb]: hey, thezip
[perldigious]: I don't miss having to drive up and down in elevation on roads that are iced over, I white knuckled gripping the steering wheel every time I had to where I used to live.
[perldigious]: So I don't envy you mountain guys if you have to drive in the winter, even with tire chains.
MidLifeXis waves.
[stevieb]: man, I absolutely LOVE driving in the worst winter conditions. In the mountainous roads, there are extremely few (if any) other drivers. I love the challenge. I've been doing extreme off-road my whole life, and as I said, I'm always well...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2016-12-06 16:40 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (112 votes). Check out past polls.