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

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

    Short answer: node.js fs.rmdir() calls the POSIX rmdir(); this will remove an empty directory, or return an error. In the given case, the call will invoke the callback function and pass the error as an exception.

    The problem here is that the node.js documentation refers to POSIX:

    The Node.js API Docs File System API started out as

    simple wrappers around standard POSIX functions.

    This almost changes the question into a duplicate of: Is there a listing of the POSIX API / functions?

    The description for fs.rmdir is terse, but sufficient.

    Asynchronous rmdir(2).

    The rmdir(2) here is an implicit reference to the documentation for the rmdir() system call. The number (2) here is an old unix man page convention to indicate Section 2 of the Manual pages, containing the kernel interfaces.

提交回复
热议问题