1

If you create multiple directories within each other using Powershell is it possible to remove them all at once? The rmdir command removes them one at a time, but I was wondering if there was a more simple way.

Thank you!

I'm just learning to code through Powershell, so any tips or tricks are appreciated!

1
  • 1
    I would think this is not possible since it can only perform one action at a time. When highlighting folders for deletion in windows it still has to remove them one at a time. A better question would be why do you want to do this? In case there is another approach we could take to satisfy whatever your need is. Commented Jan 26, 2015 at 19:02

1 Answer 1

1

If by WITHIN each other you mean directories that all share a common ancestor, you can delete the common ancestor and all descendants recursively:

Remove-Item -Recurse -Force DirectoryToDelete

Note that this can also be done using the rmdir command with the /s switch.

Sign up to request clarification or add additional context in comments.

3 Comments

I meant more like directories that have one directory within each of them. I tried rmdir, but it's possible that I was typing the directories incorrectly, but for example if you have the directories joe/jeff/john would you just rmdir joe/jeff/john?
In your example, is the jeff folder contained in the joe folder and the john folder contained in the jeff folder, or are they directories that are on the same level?
So, I realized what I was doing wrong. When trying to remove the directories I would input rmdir joe/jeff/john, but instead all I had to do was Joe. Thanks for the quick response!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.