簡體   English   中英

使用PowerShell命令刪除文件或文件夾

[英]Delete a file or folder using PowerShell command

我想使用PowerShell命令刪除特定文件夾中的文件,但是當我使用Remove-Item $DownloadFilePath* -recurs (其中$DownloadFilePath攜帶文件夾的路徑)刪除文件時,它將刪除文件夾本身和在其父文件夾中的文件。 請讓我知道僅刪除文件夾內文件的解決方案。

這應該只刪除$DownloadFilePath的內容:

Remove-Item $DownloadFilePath\* -Recurse

如果只想刪除文件而沒有子文件夾,則可以使用:

$DownloadFilePath = 'S:\Test\Folder'
Get-ChildItem -Path $DownloadFilePath -File -Recurse | Remove-Item

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM