我正在尝试使用Powershell v5.1压缩文件夹,但是一些文件正在被其他进程使用,导致PS无法强制或忽略它们。
Get-ChildItem "C:\folder" | Compress-Archive -DestinationPath "C:\file.zip"
同时尝试使用 -Force
和 -ErrorAction Ignore,Continue,SilentlyContinue
,但每次都会出现如下错误:
ZipArchiveHelper:由于另一个进程正在使用它,因此无法访问文件“C:\ folder \ filexyz”。 位于 C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:69 6 char:30 + ... sArchived = ZipArchiveHelper $subDirFiles.ToArray() $destinationPath ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (C:\folder\filexyz:String) [Write-Error], IOException + FullyQualifiedErrorId : CompressArchiveUnauthorizedAccessError,ZipArchiveHelper New-Object:使用“1”个参数调用“.ctor”时发生异常:“流不可读取。” 位于 C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:80 7 char:38 + ... $srcStream = New-Object System.IO.BinaryReader $currentFileStream + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [New-Object],MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Ignore/Continue
(或Ignore
)。您尝试过SilentlyContinue
吗? - Ansgar WiechersGet-ChildItem -Path C:\folder -ErrorAction SilentlyContinue | Compress-Archive -Destination D:\file.zip
- Maximilian BurszleyCompressArchiveUnauthorizedAccessError
这意味着您无法访问D:\
。 - Maximilian Burszley