Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

makecab - create a cab file from all the files in a folder

I have bunch of files in a directory. I tried following makecab but it does not include all the files in a folder into the cab file.

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

The following works but the cab file only has the manifest file. makecab manifest.xml test.cab

like image 367
torres Avatar asked Oct 16 '13 18:10

torres


People also ask

How do I turn a folder into a CAB file?

You can also click to select ZIP files using your operating system's file picker. Another method is to press the keyboard shortcut Ctrl+V (⌘+V on Mac) to paste a ZIP file you have copied to clipboard. Converting a folder with ZIP files to CAB is also supported: simply paste or drag and drop it.

How do I create a CAB file using Makecab exe?

To create a DIAGCAB file, use the Makecab.exe or Cabarc.exe tool. For details, see Microsoft Cabinet Format. The makecab.exe tool is located in the %Windir%\System32 folder. You should sign the cabinet file so if it is downloaded from the Web, the user knows that it came from a trusted source.


2 Answers

I've finally created a script that can actually do this properly (with powershell)

It doesn't use WSPBuilder as I'm often contracted out and it's inconvenient to download new software/extra files. This works 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
}

please let me know if i'm doing something wrong and/or could be better.

for reference:

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

NOTE: Change made by Jerry Cote, see edit notes

like image 190
Nacht Avatar answered Oct 19 '22 18:10

Nacht


/d switch cannot be used for files:

@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 can be found a script that preserves the whole directory structure

like image 25
npocmaka Avatar answered Oct 19 '22 18:10

npocmaka