2013-10-16 169 views
14

我在目录中有一堆文件。我尝试了下面的makecab,但它并没有将文件夹中的所有文件都包含在cab文件中。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

回答

12

/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

EDIThere可以发现,保留整个目录结构的脚本

+0

在 “files.txt” 的某些情况下,文件路径和名称添加到 “files.txt” 为好。然后files.txt也会在test.cab中。 – Hinek

22

我终于创建了一个脚本,可以真正做到这一点(使用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 | ? {!$_.psiscontainer}|select -expand fullname|%{'"'+$_+'" "'+$_.SubString($dirfullname.length+1)+'"'}) -join "`r`n" 
    $ddf 
    $ddf | Out-File -encoding UTF8 $ddfpath 
    makecab /F $ddfpath 
    rm $ddfpath 
    rm setup.inf 
    rm setup.rpt 
} 

请让我知道如果我做错了什么和/或可能会更好。

参考

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

+7

这很漂亮,但是,用法: 打开PowerShell; 将此功能粘贴到PowerShell中; 按回车键; compress-directory。\ some-dir-to-compress。\ filename.cab – turiyag

+1

只有一些使用问题需要注意,如果有人在这个旧帖子中运行。目的地不会采取文字路径。您可以推/拉一个位置作为解决方法。命令将看起来像“压缩目录c:\ temp。\ temp.cab”
此外cab文件超过2千兆字节 - 512字节时有问题。作为附加选项,可以设置压缩类型LZX作为替代。 – Lorek

相关问题