小编Phy*_*iik的帖子

Powershell - 跳过无法访问的文件

我试图用Powershell递归删除文件夹内的所有文件和文件夹.我正在尝试一个简单的工作:

Remove-Item "C:\Users\user\Desktop\The_folder\*" -Recurse -Force
Run Code Online (Sandbox Code Playgroud)

我的问题是每当我运行它时,我得到:

Cannot remove item C:\Users\user\Desktop\The_folder\Delete: The process cannot access the file 'C:\Users\user\Desktop\The_folder\Delete' because it is being used by another process.
Run Code Online (Sandbox Code Playgroud)

如何跳过我无法访问的任何文件(可能是因为它们正在使用中)?用户在弹出窗口中执行的方式与询问是否要跳过无法访问的所有文件的方式相同.

谢谢!

编辑:我试过:

Remove-Item "C:\Users\mstjean\Desktop\The_folder\*" -Recurse -Force -ErrorAction Continue
Run Code Online (Sandbox Code Playgroud)

Remove-Item:无法删除项目C:\ Users\mstjean\Desktop\The_folder\Delete:进程无法访问文件'C:\ Users\mstjean\Desktop\The_folder\Delete',因为它正由另一个进程使用.在行:1 char:1 + Remove-Item"C:\ Users\mstjean\Desktop\The_folder*" - Recurse -Force -ErrorAction ... +

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:WriteError:(C:\ Users\mstjea ... e_folder\Delete:DirectoryInfo )[Remove-Item],IOException + FullyQualifiedErrorId:RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand

但我得到了这个错误.

powershell

15
推荐指数
1
解决办法
2万
查看次数

标签 统计

powershell ×1