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

后端 未结 22 1413
清歌不尽
清歌不尽 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:47

    Removing NON-EMPTY directories SYNCHRONOUSLY:-

    Following is the file structure -

    var fs = require('fs');
    
    fs.unlink('./stuff/writeMe.txt',function(){
      fs.rmdirSync('stuff');
    })
    

    I am firstly removing the writeMe.txt file from stuff folder using code fs.unlink('./stuff/writeMe.txt') which makes the stuff folder empty and finally removing it using code fs.rmdirSync('stuff')

提交回复
热议问题