小编orb*_*ron的帖子

Powershell:IOException try/catch无效

我有一个PS脚本,每5分钟启动一次,检查新删除的文件夹并移动它们.问题是有时文件夹中的项目仍在写入,在这种情况下脚本错误:

Move-Item:进程无法访问该文件,因为它正由另一个进程使用.[Move-Item],IOException + FullyQualifiedErrorId:MoveDirectoryItemIOError,Microsoft.PowerShell.Commands.MoveItemCommand

我尝试了以下try/catch块,但它仍然在同一个"Move-Item"行上出错.对我在这里做错了什么的想法?

          try {
           Move-Item -Force "$fileString" $fileStringFixed
          }
          catch [System.IO.IOException] {
           return
          }
Run Code Online (Sandbox Code Playgroud)

谢谢.

powershell

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

标签 统计

powershell ×1