现在的ai还是太弱智了, 试了快上百轮了, 就是不行, 下面代码能转成, 但是用密码打不开, 哎 | function Convert-ZipTo7z { | | param ( | | [string]$zipPath | | ) | | | | | | if (-Not (Test-Path $zipPath)) { | | Write-Host "文件 $zipPath 不存在" | | exit 1 | | } | | | | | | $fileName = [System.IO.Path]::GetFileNameWithoutExtension($zipPath) | | | | | | $password = $fileName.Substring(0, 6) | | | | | | $output7zPath = [System.IO.Path]::ChangeExtension($zipPath, ".7z") | | | | | | $tempDir = New-Item -ItemType Directory -Path ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())) | | | | try { | | | | & 7za x $zipPath -o"$tempDir" | Out-Null | | | | | | & 7za a -t7z -p$password -mhe=on $output7zPath "$tempDir\*" | Out-Null | | | | Write-Host "转换完成: $output7zPath" | | } | | finally { | | | | Remove-Item -Recurse -Force $tempDir | | } | | | | | | return $output7zPath | | } | | | | | | $zipPath = "C:\Users\Administrator\Desktop\ab.cdef_25.05.03.zip" | | $output7zPath = Convert-ZipTo7z -zipPath $zipPath | | | | Write-Host "输出文件路径: $output7zPath"COPY |
|