【问题标题】:Compress-Archive error: PermissionDenied压缩存档错误:PermissionDenied
【发布时间】:2018-07-18 23:47:23
【问题描述】:
我正在尝试使用 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 个字符:30
+ ... sArchived = ZipArchiveHelper $subDirFiles.ToArray() $destinationPath ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\folder\filexyz:String) [Write-Error], IOException
+ FullyQualifiedErrorId : CompressArchiveUnauthorizedAccessError,ZipArchiveHelper
新对象:使用“1”参数调用“.ctor”的异常:“流不可读。”
在 C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:80
7 个字符:38
+ ... $srcStream = 新对象 System.IO.BinaryReader $currentFileStream
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
【问题讨论】:
-
没有错误操作Ignore/Continue(或Ignore)。你试过SilentlyContinue吗?
-
-
Get-ChildItem -Path C:\folder -ErrorAction SilentlyContinue | Compress-Archive -Destination D:\file.zip
-
另外,您的访问被拒绝,而不是文件在使用中。 CompressArchiveUnauthorizedAccessError 这意味着您无权访问 D:\
-
我修复了那个例子...我在任何地方都有完全访问权限-管理员
标签:
powershell