2013-10-16 167 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

相關問題