简体   繁体   中英

Delete a file or folder using PowerShell command

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.

这应该只删除$DownloadFilePath的内容:

Remove-Item $DownloadFilePath\* -Recurse

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM