1

I want to delete the files which are in a particular folder using PowerShell commands, but when I use Remove-Item $DownloadFilePath* -recurs (where $DownloadFilePath carries the path of the folder) to delete files then it deletes the folder itself and the files which are in its parent folder. Please let me know the solution to just delete files inside the folder.

2 Answers 2

1

And if you only want to remove files but no sub folders you can use:

$DownloadFilePath = 'S:\Test\Folder'
Get-ChildItem -Path $DownloadFilePath -File -Recurse | Remove-Item
Sign up to request clarification or add additional context in comments.

Comments

0

This should delete just the contents of $DownloadFilePath:

Remove-Item $DownloadFilePath\* -Recurse

2 Comments

I tried that but the error comes and execution of script doesn't stop
What error, and why would you want the script to stop?

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.