【问题标题】:Powershell Command Line Winrar not creating file in expected locationPowershell 命令行 Winrar 不在预期位置创建文件
【发布时间】:2015-02-05 05:01:36
【问题描述】:

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

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

$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..."
}

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

【问题讨论】:

    标签: powershell command-line zip winrar


    【解决方案1】:

    在脚本运行时找出你所在的目录,添加:

    resolve-path .
    

    到你的脚本。

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

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

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

    【讨论】:

    • 是的,你是对的,它正在将文件输出到 Powershell 脚本所在的目录中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-21
    相关资源
    最近更新 更多