我正在尝试构建一个简单的脚本,在该脚本中,我根据用户在输入时提供的密码来测试多个目录中的所有.7z存档。当前,如果这些归档文件与脚本位于同一目录中,则该脚本仅能处理这些归档文件,否则无论密码是否正确,我都会得到以下输出:
================================================================ 7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18 Error: cannot find archive Directory:\Documents\Project\FOLDER1 Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 06/08/2018 16:30 223 Alpha.7z Wrong Password! ================================================================
请查看我的代码,并告诉我我要去哪里哪里
$CaseDirectory = Read-Host 'Please input Case directory'
$Password = Read-Host 'Please input Case password'
$7ZipPath = "C:\Program Files\7-Zip\7z.exe"
$Files = Get-ChildItem -Path $CaseDirectory -Recurse -Force -Filter *.7z
$Output = Foreach ($File in $Files)
{
& $7ZipPath "t" $File "-p$Password"
if (-not $?)
{
Write-Output $File "Wrong Password!"
} else {
Write-Output $File "Password Match"
}
Write-Output "================================================================"
}
$Output | findstr /r /v "^$" | Out-File -FilePath $CaseDirectory\PasswordTest_Output.txt
pause
答案 0 :(得分:2)
更改
& $7ZipPath "t" $File "-p$Password"
进入
& $7ZipPath "t" $File.FullName "-p$Password"
使用文件Get-ChildItem给出的完整路径