首页 > 解决方案 > 在 powershell 中使用 7-zip

问题描述

我想从 csv.gz zip 文件中提取 csv 文件。我已经下载了 7-zip 并尝试使用以下代码:

$7zprogram = "C:\Program Files\7-Zip\7z.exe"
$sourcefile = "C:\Users\Mitesh\Desktop\file.csv.gz"
$destination = "C:\Users\Mitesh\Desktop\"

& $7zprogram e $sourcefile "-o$destination"

这不起作用,我收到一条错误消息,因为“术语“C:\Program Files\7-Zip\7z.exe”未被识别为 cmdlet、函数......”。

可能是什么问题?如果缺少某些内容,有人可以帮我更正这里的代码。

标签: powershell7zip

解决方案


听起来Powershell找不到7z.exe。

您可以使用以下版本的代码来测试这个理论:

$7zprogram = "C:\Program Files\7-Zip\7z.exe"
$sourcefile = "C:\Users\Mitesh\Desktop\file.csv.gz"
$destination = "C:\Users\Mitesh\Desktop\"


if(Test-Path -Path $7zprogram){
    & $7zprogram e $sourcefile "-o$destination"
}else{
    Write-Host "7z.exe does not exist";
}

我假设它会输出7z.exe does not exist。如果是这样,请确保您安装了 7zip,并且它的文件名和路径正确(我测试了您的命令并且它在语法上是正确的/应该可以工作)。您的问题几乎可以肯定是这一行:$7zprogram = "C:\Program Files\7-Zip\7z.exe"


推荐阅读