gpt4 book ai didi

powershell - 从脚本位置 powershell 创建 zip

转载 作者:行者123 更新时间:2023-12-03 05:04:16 25 4
gpt4 key购买 nike

我有一个 PowerShell 脚本,它应该能够创建特定文件夹的 zip,该文件夹也位于同一位置。但问题是我不知道这个脚本将保存在哪里。我尝试了下面的代码,但我无法做到这一点。 Compress-Archieve 方法显示参数为 null 或为空。请帮忙。

Add-Type -AssemblyName System.IO.Compression.FileSystem
$source = Get-ChildItem -Filter -Directory .\PublishOutput
$dest = Get-Location
$f = "\Kovai.zip"
$final = Join-Path $dest $f
Write-Host $final
[System.IO.Compression.ZipFile]::CreateFromDirectory($source,$final)

最佳答案

$folderToZip = "C:\FolderToZip"
$rootfolder = Split-Path -Path $folderToZip
$zipFile = Join-Path -Path $rootfolder -ChildPath "ZippedFile.zip"

Write-Output "folderToZip = $folderToZip"
Write-Output "rootfolder = $rootfolder"
Write-Output "zipFile = $zipFile"

Compress-Archive -Path $folderToZip -DestinationPath $zipFile -Verbose

Results

关于powershell - 从脚本位置 powershell 创建 zip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48537340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com