现在的ai还是太弱智了, 试了快上百轮了, 就是不行, 下面代码能转成, 但是用密码打不开, 哎- function Convert-ZipTo7z {
- param (
- [string]$zipPath
- )
-
- # 检查 zip 文件是否存在
- if (-Not (Test-Path $zipPath)) {
- Write-Host "文件 $zipPath 不存在"
- exit 1
- }
-
- # 获取文件名(不包括路径和扩展名)
- $fileName = [System.IO.Path]::GetFileNameWithoutExtension($zipPath)
-
- # 获取文件名前 6 位作为密码
- $password = $fileName.Substring(0, 6)
-
- # 设置输出的 7z 文件路径
- $output7zPath = [System.IO.Path]::ChangeExtension($zipPath, ".7z")
-
- # 创建一个临时目录来解压缩 zip 文件
- $tempDir = New-Item -ItemType Directory -Path ([System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName()))
-
- try {
- # 解压缩 zip 文件到临时目录
- & 7za x $zipPath -o"$tempDir" | Out-Null
-
- # 使用 7za 命令行工具将解压后的文件压缩为 7z 加密文件,并加密文件名
- & 7za a -t7z -p$password -mhe=on $output7zPath "$tempDir\*" | Out-Null
-
- Write-Host "转换完成: $output7zPath"
- }
- finally {
- # 删除临时目录
- Remove-Item -Recurse -Force $tempDir
- }
-
- # 返回转换后的 7z 文件路径
- return $output7zPath
- }
-
- # 调用函数并传递 zip 文件的路径作为参数
- $zipPath = "C:\Users\Administrator\Desktop\ab.cdef_25.05.03.zip"
- $output7zPath = Convert-ZipTo7z -zipPath $zipPath
-
- Write-Host "输出文件路径: $output7zPath"
复制代码
|