How can I delete all files and subfolders in a directory while keeping the main folder?

0
21
Asked By DoodleBug87 On

I'm trying to figure out how to use PowerShell to remove all files and folders inside a specific directory without deleting the directory itself. For example, I have a directory at c:keepthisdirectory and I want to remove everything inside it but keep the main directory intact. Is there a command that can help me do this?

1 Answer

Answered By CleverTechie On

You can achieve this with the command `Remove-Item -path c:keepthisdirectory* -recurse`. The `*` wildcard targets everything inside the specified directory while keeping the directory itself safe. The `-Recurse` parameter ensures that everything within is removed without affecting the main folder itself.

DoodleBug87 -

Precisely what I was looking for. Thank you so much!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.