Skip to content

An optional parameter that lets us delete folders that aren't empty directly #22686

Closed
@ghost

Description

Until now in Node 8.x, we CANNOT directly delete a folder with the sub folders with files. I'm not sure whether we can offer such a function because this is a common behaviour to delete a folder that is NOT empty (Considering the performance, we can write our core codes at C++ layer, and call it through js aspect).

For we've got rmdirSync or rmdir, maybe we can add an optional parameter to choose whether we allow to remove sub files/folders for the parent folder itself or not (In order to be compatible with it, the default value should be false, this means when you remove a folder that isn't empty, error will be thrown out like what can see now), something like this following:

import { rmdirSync } from "fs";
rmdirSync('d:/tryme',true); // The second parameter will let you allow to delete a folder that isn't empty, the default value is false.

PS:I know that some 3-rd parties have implemented this, but it would be better inject it into the nodejs's fs module, which is very useful and pratical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions