Skip to content

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

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.

Activity

  1. Trott commented on Sep 4, 2018

    @Trott
    Member

    If we end up doing this, please no Boolean trap in the API signature. Use an options object instead.

  2. apapirovski commented on Sep 4, 2018

    @apapirovski
    Contributor

    So basically rimraf? This is a pretty regular request around here. As far as an API — it should just be a separate function, much like mkdirp.

  3. richardlau commented on Sep 4, 2018

    @richardlau
    Member

    As far as an API — it should just be a separate function, much like mkdirp.

    That's not how we implemented recursive mkdir (#21875) -- the current code on master uses an options parameter (see also discussions in #22302 and #22585).

  4. boneskull commented on Sep 4, 2018

    @boneskull
    Member

    I am working on a rimraf impl

  5. apapirovski commented on Sep 5, 2018

    @apapirovski
    Contributor

    That's not how we implemented recursive mkdir (#21875) -- the current code on master uses an options parameter (see also discussions in #22302 and #22585).

    I'm aware but that's also the reason it hasn't been released. Given the feature testing angle, it's almost certain to land in an actual release as a separate function.

  6. boneskull commented on Sep 5, 2018

    @boneskull
    Member

    it's almost certain to land in an actual release as a separate function.

    Was a decision made on this? It seemed to be still under consideration...

  7. apapirovski commented on Sep 5, 2018

    @apapirovski
    Contributor

    Was a decision made on this? It seemed to be still under consideration...

    I'm interpolating from the available data points... 😆

    Someone should just open the PR at this point. I will later this week if no one gets to it before then.

  8. added
    fsIssues and PRs related to file-system APIs and the fs module.
    feature requestIssues requesting new Node.js features.
    on Sep 7, 2018
  9. shisama commented on Nov 9, 2018

    @shisama
    Contributor

    I had been waiting for the PR someone open. However, it seems not to be opened. So, I implemented on #24252
    Please mention to me if someone open the PR implementing this.

  10. silverwind commented on May 18, 2019

    @silverwind
    Contributor

    So the conclusion of #24252 is that doing it in C++ was not fast enough? Should a future attempt at this feature still be in C++ or would we be open to a JS-only solution too?

  11. shisama commented on May 22, 2019

    @shisama
    Contributor

    So the conclusion of #24252 is that doing it in C++ was not fast enough?

    Yes. #24252 implementation was not faster than rimraf because the implementation in C++ deletes directories sequentially. rimraf does in parallel.

  12. silverwind commented on May 22, 2019

    @silverwind
    Contributor

    I guess we could make an attempt at porting rimraf to core, including its retry logic. @boneskull I see you mentioned attempting it, did you get anywere?

  13. iansu commented on Jul 24, 2019

    @iansu
    Contributor

    This is currently in progress here: #28208

  14. richardlau commented on Nov 7, 2019

    @richardlau
    Member

    Implemented in #29168.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions