isaacs/rimraf

Can't rimraf parent directory

tbetous opened this issue · 3 comments

When I try to use riram into a parent directory it does not work.

For instance I have this tree :

toto/
+--- tata/
     +--- test.txt
     +--- test.js

In my test.js I have this :

const rimraf = require('rimraf')

rimraf(`${__dirname}/../`, console.log)

All files in toto will be deleted but not toto directory.

Plus when I execute rimraf ../ when I am into tata directory I have this :

.nvm/versions/node/v10.15.3/lib/node_modules/rimraf/bin.js:47
      throw er
      ^

Error: ENOTEMPTY: directory not empty, rmdir '../'

With the same result. All files in toto will be deleted but not toto directory.

How can I delete parent directory ?

KCGD commented

this could be due to how window's file system works (im assuming this is on windows), the javascript file running would be considered in-use by a process and wouldn't be allowed to be deleted, and you cant really delete a directory without all the files in the directory being deleted too.

So basically; the code running is considered in-use and cant be deleted (on windows)
also this same thing happens for any in-use file in the directory so just be careful of that

node v12 works,node v14 doesn't work

If there's a process running in cwd, then that will lock the directory and prevent its removal on Windows. Chdir out of it first.