【问题标题】:makecab - create a cab file from all the files in a foldermakecab - 从文件夹中的所有文件创建一个 cab 文件
【发布时间】:2013-10-25 00:59:12
【问题描述】:

我在一个目录中有一堆文件。我尝试关注makecab,但它没有将文件夹中的所有文件都包含到cab文件中。

makecab /d "C:\Users\crtorres\Documents\- SouthPacific Project 2014\- Projects\Sales Doc Center\New Region" test.cab

以下工作,但 cab 文件只有清单文件。 makecab manifest.xml test.cab

【问题讨论】:

    标签: batch-file cab makecab


    【解决方案1】:

    我终于创建了一个实际上可以正确执行此操作的脚本(使用 powershell)

    它不使用 WSPBuilder,因为我经常外包,下载新软件/额外文件不方便。这适用于 OOTB。

    function compress-directory([string]$dir, [string]$output)
    {
        $ddf = ".OPTION EXPLICIT
    .Set CabinetNameTemplate=$output
    .Set DiskDirectory1=.
    .Set CompressionType=MSZIP
    .Set Cabinet=on
    .Set Compress=on
    .Set CabinetFileCountThreshold=0
    .Set FolderFileCountThreshold=0
    .Set FolderSizeThreshold=0
    .Set MaxCabinetSize=0
    .Set MaxDiskFileCount=0
    .Set MaxDiskSize=0
    "
        $dirfullname = (get-item $dir).fullname
        $ddfpath = ($env:TEMP+"\temp.ddf")
        $ddf += (ls -recurse $dir | where { !$_.PSIsContainer } | select -ExpandProperty FullName | foreach { '"' + $_ + '" "' + ($_ | Split-Path -Leaf) + '"' }) -join "`r`n"
        $ddf
        $ddf | Out-File -Encoding UTF8 $ddfpath
        makecab.exe /F $ddfpath
        rm $ddfpath
        rm setup.inf
        rm setup.rpt
    }
    

    如果我做错了什么和/或可以做得更好,请告诉我。

    供参考:

    http://www.pseale.com/blog/StrongOpinionSayNoToMAKECABEXE.aspx

    注意:Jerry Cote 所做的更改,请参阅编辑说明

    【讨论】:

    • 这很漂亮,但是,用法:打开PowerShell;将此函数粘贴到 PowerShell 中;按回车;压缩目录 .\some-dir-to-compress .\filename.cab
    • 如果有人遇到此旧帖子,请注意一些使用问题。 Destination 不会采用文字路径。您可以推送/弹出位置作为解决方法。命令看起来像“compress-directory c:\temp .\temp.cab”
      此外,当超过 2 GB - 512 字节时,cab 文件会出现问题。作为附加选项,可以将压缩类型 LZX 设置为备选方案。
    • 这个脚本是压缩目录本身还是压缩目录下的所有内容?换句话说,它是压缩dir/还是dir/*
    • @Chromium 试试看。它似乎在做dir/*。还有为什么没有人告诉我我有一个删除每个文件名的第一个字符的错误!现已修复。
    • @turiyag 另外,您似乎需要在粘贴函数后按两次Enter
    【解决方案2】:

    /d 开关不能用于文件:

    @echo off
    dir /s /b /a-d >files.txt
    makecab /d "CabinetName1=test.cab" /f files.txt
    del /q /f files.txt
    

    More info

    EDIT here 可以找到一个保留整个目录结构的脚本

    【讨论】:

    • 在某些情况下,“files.txt”的文件路径和名称也会添加到“files.txt”中。然后 files.txt 也将在 test.cab 中。
    猜你喜欢
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 2014-04-03
    • 2022-01-11
    相关资源
    最近更新 更多