【发布时间】:2017-05-05 12:40:41
【问题描述】:
我有一个 PowerShell 脚本,它应该解压缩目录中的一些文件,但是当我运行它时会抛出这个错误:
Exception calling "ExtractToDirectory" with "2" argument(s): "Access to the path
'E:\SubFolder\SubFolder2\SubFolder3' is denied."
At line:7 char:5
+ [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, "E:\SubFolder\Sub ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : UnauthorizedAccessException
我已经完全控制了路径中的每个单独的文件夹并以管理员身份运行(只是为了测试),但它仍然会引发错误。
这是我的代码
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, "E:\SubFolder\SubFolder2\SubFolder3")
}
$Files = get-childitem "E:\SubFolder\SubFolder2\SubFolder3"
foreach ( $i in $files )
{
Unzip "SubFolder\SubFolder2\SubFolder3\$i"
}
有人可以为我指明正确的方向以使其正常工作吗?
【问题讨论】:
-
我无法复制错误,但可以尝试在
Get-ChildItem中添加Where子句:get-childitem "E:\SubFolder\SubFolder2\SubFolder3" | Where { $_.Extension -eq ".zip" } -
成功了。在下面发布您的答案,我会接受。谢谢!