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
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.
Precisely what I was looking for. Thank you so much!