Powershell 命令行 Winrar 未在预期位置创建文件

Powershell Command Line Winrar not creating file in expected location

我有一个 Powershell 脚本,它应该在指定位置压缩指定目录,看起来好像 WinRAR 运行 并执行某种操作,但是我似乎无法找到压缩文件的位置最终出现在文件系统中。

我的想法是,我将压缩一个目录,然后从文件系统中删除解压后的目录。

$filePath 变量是要压缩的目录的位置(包括基本位置),$rarExePath 是 WinRAR.exe

的路径
# zips up any files in the directory
function ZipDirectory($filePath, $rarExePath)
{
    "Zipping directory $filePath"

    #$zipFilePath = (Split-Path $filePath -Parent)

    $archiveName = (Split-Path $filePath -Leaf) + ".rar"

    "Zipping directory $dirPath to file $archiveName $zipFilePath"

    Start-Process $rarExePath -ArgumentList "a -r $archiveName $filePath"

    #Remove-Item -Recurse $filePath

    "Completed..."
}

我的命令有什么明显的错误吗?

当脚本为 运行 时,通过添加:

找出您所在的目录
resolve-path .

到你的脚本。

很有可能 WinRAR 只是将文件放入当前目录,而您不知道那是什么。

我将更改 $archiveName 变量以添加 显式 我希望创建文件的路径:

PS C:\Users\pax> $x = 'c:\desired\' + (split-path "c:\a\b\xyzzy" -leaf)

PS C:\Users\pax> $x
C:\desired\xyzzy