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

后端 未结 22 1375
清歌不尽
清歌不尽 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 13:43

    fs.rmdir is not recursive.

    You could instead use a recursive fs.readdir module like readdirp in order to find all files and directories . Then remove all files, followed by all directories.

    For an even simpler solution have a look at rimraf.

提交回复
热议问题