Is node.js rmdir recursive ? Will it work on non empty directories?

后端 未结 22 1818
清歌不尽
清歌不尽 2021-01-31 13:41

The documentation for fs.rmdir is very short and doesn\'t explain the behavior of rmdir when the directory is not empty.

Q: What happens if I try to use

22条回答
  •  情书的邮戳
    2021-01-31 14:03

    Although using a third-party library for such a thing I could not come up with a more elegant solution. So I ended up using the npm-module rimraf.

    Install it

    npm install rimraf
    

    Or install it and save to 'package.json' (other save options can be found in the npm-install docs)

    npm install --save rimraf
    

    Then you can do the following:

    rmdir = require('rimraf');
    rmdir('some/directory/with/files', function(error){});
    

    Or in Coffeescript:

    rmdir = require 'rimraf'
    rmdir 'some/directory/with/files', (error)->
    

提交回复
热议问题