Reputation: 11
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.
Upvotes: 1
Views: 8059
Reputation: 14695
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
Upvotes: 1
Reputation: 200193
This should delete just the contents of $DownloadFilePath
:
Remove-Item $DownloadFilePath\* -Recurse
Upvotes: 0