23

我在一个目录中有一堆文件。我尝试关注 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

4

2 回答 2

33

我终于创建了一个实际上可以正确执行此操作的脚本(使用 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 所做的更改,请参阅编辑说明

于 2014-07-10T05:17:34.783 回答
19

/d 开关不能用于文件:

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

更多信息

在这里编辑可以找到一个保留整个目录结构的脚本

于 2013-11-07T14:04:15.673 回答