You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell提取无.zip后缀压缩文件报格式不支持的解决方法

报错原因

Expand-Archive 原生cmdlet仅通过文件扩展名识别压缩包格式,不会校验文件实际内容,只要传入的文件路径不带.zip后缀,就会直接抛出“不支持的归档文件格式”错误,和文件本身是不是合法ZIP压缩包无关。

可行解决方法

方法1:临时生成带.zip后缀的副本后解压

不需要改动原文件,解压完成后自动清理临时文件,兼容性最好:

$sourceFile = "\\ccaintranet.com\dfs-dc-01\Split\Retail\FTP-FromClient\OracleRMS\Extraction\2022-04-30\CONNOLLY_20220429191553"
$destPath = "\\ccaintranet.com\dfs-dc-01\Split\Retail\FTP-FromClient\OracleRMS\Extraction\2022-04-30\"
# 生成随机临时zip路径
$tempZipPath = Join-Path $env:TEMP "$([guid]::NewGuid().ToString('N')).zip"

try {
    Copy-Item -Path $sourceFile -Destination $tempZipPath -Force
    Expand-Archive -Path $tempZipPath -DestinationPath $destPath -Force
}
finally {
    # 自动清理临时文件
    if (Test-Path $tempZipPath) {
        Remove-Item $tempZipPath -Force
    }
}

方法2:直接调用.NET类解压,无需改动文件

.NET内置的ZIP处理类会识别文件真实格式,不依赖后缀名,代码更简洁,适合PowerShell 5.1及以上版本:

# 加载压缩功能所需程序集
Add-Type -AssemblyName System.IO.Compression.FileSystem
$sourceFile = "\\ccaintranet.com\dfs-dc-01\Split\Retail\FTP-FromClient\OracleRMS\Extraction\2022-04-30\CONNOLLY_20220429191553"
$destPath = "\\ccaintranet.com\dfs-dc-01\Split\Retail\FTP-FromClient\OracleRMS\Extraction\2022-04-30\"

# 最后一个参数$true代表强制覆盖已存在文件,不需要覆盖可改为$false
[System.IO.Compression.ZipFile]::ExtractToDirectory($sourceFile, $destPath, $true)

注意:如果执行时报路径访问权限错误,先确认当前运行PowerShell的账号对源文件有读取权限、对目标解压路径有写入权限即可。

内容的提问来源于stack exchange,提问作者Dikshit Karki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 19:54:23