Skip to content

Can't delete non-empty folders #788

@justDeek

Description

@justDeek

Hey folks,

I've created an item that removes all temporary/auto-generated folders inside dev-projects, but the problem is, that it only removes the folders if they are empty.

I have tried various things, each of them only working on files and non-empty folders, but failing once a folder contains at least one item.
I'm on Windows 11 if that's relevant.

This was my first approach (I abbreviated the items list with <...>):

item(title="Clean Project" image=\uE0CE admin cmd={
    $items = [
      "__pycache__",
      ".cargo",
      "node_modules",
      <...>
    ]
    for(i=0, i<len(items)) {
      $currPath = path.join(sel.curdir, items[i])
      io.delete(currPath)
    }
    command.refresh
  })

Then based on a code snipped by RubicBG I created this alternative approach using PowerShell:

item(title="Clean Project" image=\uE0CE commands {
    admin cmd-ps=`Remove-Item -Path "@sel.curdir/__pycache__",
    "@sel.curdir/.cargo",
    <...>
     -Recurse -Force -ErrorAction SilentlyContinue`
    window='hidden' wait=1
  })

This approach works when running it manually in a PowerShell window, but not via NSS (though it does prompt whether or not to remove nested files when the -Recurse flag isn't set).

When asking Perplexity AI, it came up with this approach:

  $currPath = path.join(sel.curdir, "node_modules")
  cmd("cmd.exe /c rmdir /s /q \"" + currPath + "\"")

I tried all these variants with and without the 'admin' flag and with only one item instead of iterating through an array, but still the same issue.

I also looked into creating a recursive function to remove all nested items manually, but NSS doesn't seem to allow for creating custom functions.

Maybe one of you could have a look at it or try it yourself. Could be a problem with my system or a bug in NSS.
It would also be helpful if the io.delete function would have a recursive parameter (similar to io.copy).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions