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

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

    Figured this was a good excuse to take a dive into the source ;)

    From what I can tell, fs.rmdir is bound to the rmdir function from unistd.h. From the POSIX man page for rmdir:

    The rmdir() function shall remove a directory whose name is given by path. The directory shall be removed only if it is an empty directory.

    If the directory is not an empty directory, rmdir() shall fail and set errno to [EEXIST] or [ENOTEMPTY].

提交回复
热议问题