MakeCab: Compressing large folders into single .CAB file for less size on the disk

One needs to create a DIAMOND DIRECTIVE FILE (*.DDF) which is used as a configuration file by makecab.exe to set the runtime environment as defined in the .ddf file.

 

Example:

Source Folder contents to be compress:

 

PS C:>  Get-ChildItem C:TempSkype -Recurse | Where {!$_.PsIsContainer} | Select-Object -Property FullName

FullName
——–
C:TempSkypeAppsloginindex.html
C:TempSkypeAppslogincsslogin.css
C:TempSkypeAppslogincssplatformmac.css
C:TempSkypeAppslogincssplatformwin.css
C:TempSkypeAppslogincssretinalogin.css
C:TempSkypeAppsloginimagesbackground.png
C:TempSkypeAppsloginjslogin.js
C:TempSkypeAppsloginlanguagesar.js
C:TempSkypeAppsloginlanguagesvi.js
C:TempSkypeAppsloginlanguageszh-hans.js
C:TempSkypeAppsloginlanguageszh-hant.js
C:TempSkype{4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi

PS C:>

 

DDF file:

If you do NOT specify the MaxDiskSize it’s uses 1.4M and creates multiple .cab files of 1.4MB till all the files in the source folder are converted into .cab files.

 

You can specify CabinetNameTemplate with value to be used as .cab file names instead of default numeric names for .cab files.

 

 

;*** MakeCAB Directive file
;

.Set FailOnMissingSource=On
.Set MaxErrors=1
.Set UniqueFiles=Off
.Set CompressionType=LZX
.Set CompressionMemory=21
.Set DiskDirectoryTemplate=.
.Set MaxDiskSize=2147483136                   ; File Size of
.Set CabinetNameTemplate=Compressed-Skype.cab ; Name for the compressed outfile file

.Set Cabinet=On
.Set Compress=On
.Set SourceDir="C:TempSkype"

;** The list of files are stored, compressed, in cabinet files
"Appslogincsslogin.css" "Appslogincsslogin.css"
"Appslogincssplatformmac.css" "Appslogincssplatformmac.css"
"Appslogincssplatformwin.css" "Appslogincssplatformwin.css"
"Appslogincssretinalogin.css" "Appslogincssretinalogin.css"
"Appsloginimagesbackground.png" "Appsloginimagesbackground.png"
"Appsloginindex.html" "Appsloginindex.html"
"Appsloginjslogin.js" "Appsloginjslogin.js"
"Appsloginlanguagesar.js" "Appsloginlanguagesar.js"
"Appsloginlanguagesvi.js" "Appsloginlanguagesvi.js"
"Appsloginlanguageszh-hans.js" "Appsloginlanguageszh-hans.js"
"Appsloginlanguageszh-hant.js" "Appsloginlanguageszh-hant.js"
"{4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi" "{4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi"

;…                                 ; Many more files
;*** <the end>                       ; That’s it

 

Compressing and Creating the .Cab file using the makecab command:

C:Temp>makecab /f C:TempCompress-Skype.ddf
Cabinet Maker – Lossless Data Compression Tool

20,868,956 bytes in 12 files
Total files:             12
Bytes before:    20,868,956
Bytes after:     19,365,480
After/Before:            92.80% compression
Time:                    23.79 seconds ( 0 hr  0 min 23.79 sec)
Throughput:             856.51 Kb/second

C:Temp>dir Compressed-Skype.cab
Volume in drive C has no label.
Volume Serial Number is 6E64-B572

Directory of C:Temp

30-10-2013  03:48 PM        19,371,178 Compressed-Skype.cab
               1 File(s)     19,371,178 bytes
               0 Dir(s)  193,638,236,160 bytes free

C:Temp>

image

image

 

 

You can use a detailed logging by specifying /V3 option to MakeCab file as shown below:

C:Temp>makecab /f C:TempCompress-Skype.ddf /V3 > Compressed-Skype-Makecab-verbose-Output.txt

C:Temp>

 

Notes:

  1. It is important to filter out folders from the collection because MakeCab.exe is not able to compress folders.
  2. By Default makecab creates multiple .cab files as the .cab file size exceeds 1.4 kb

 

Resources:

Microsoft MakeCAB User’s Guide

You can use the tool called CABPACK

Getting things done in PowerShell scripting: Creating CAB Files with Windows PowerShell

 

FTR,

PowerShell to get the list of ONLY files with full name recursively from the source folder that need to be compressed into .cab file.

PS C:>  Get-ChildItem C:TempSkype -Recurse | Where {!$_.PsIsContainer} | Select-Object -Property FullName  | wc -l
17
PS C:> `

 

 

Sample Verbose output:

Cabinet Maker – Lossless Data Compression Tool

PASS
1: Checking directive file(s)
———————————-
1: ;*** MakeCAB Directive file
2: ;
3:
4: .Set FailOnMissingSource=On
==> Setting variable FailOnMissingSource to ‘On’
5: .Set MaxErrors=1
==> Setting variable MaxErrors to ‘1’
6: .Set UniqueFiles=Off
==> Setting variable UniqueFiles to ‘Off’
7: .Set CompressionType=LZX
==> Setting variable CompressionType to ‘LZX’
8: .Set CompressionMemory=21
==> Setting variable CompressionMemory to ’21’
9: .Set DiskDirectoryTemplate=.
==> Setting variable DiskDirectoryTemplate to ‘.’
10: .Set MaxDiskSize=2147483136                   ; File Size of
==> Setting variable MaxDiskSize to ‘2147483136’
11: .Set CabinetNameTemplate=Compressed-Skype.cab ; Name for the compressed outfile file
==> Setting variable CabinetNameTemplate to ‘Compressed-Skype.cab’
12: .Set Cabinet=On
==> Setting variable Cabinet to ‘On’
13: .Set Compress=On
==> Setting variable Compress to ‘On’
14: .Set SourceDir="C:TempSkype"
==> Setting variable SourceDir to ‘C:TempSkype’
15:
16:
17: ;** The list of files are stored, compressed, in cabinet files
18: "Appslogincsslogin.css" "Appslogincsslogin.css"
==> FileSpec src=Appslogincsslogin.css dst=Appslogincsslogin.css
CopyCommand: C:TempSkypeAppslogincsslogin.css to Appslogincsslogin.css
19: "Appslogincssplatformmac.css" "Appslogincssplatformmac.css"
==> FileSpec src=Appslogincssplatformmac.css dst=Appslogincssplatformmac.css
CopyCommand: C:TempSkypeAppslogincssplatformmac.css to Appslogincssplatformmac.css
20: "Appslogincssplatformwin.css" "Appslogincssplatformwin.css"
==> FileSpec src=Appslogincssplatformwin.css dst=Appslogincssplatformwin.css
CopyCommand: C:TempSkypeAppslogincssplatformwin.css to Appslogincssplatformwin.css
21: "Appslogincssretinalogin.css" "Appslogincssretinalogin.css"
==> FileSpec src=Appslogincssretinalogin.css dst=Appslogincssretinalogin.css
CopyCommand: C:TempSkypeAppslogincssretinalogin.css to Appslogincssretinalogin.css
22: "Appsloginimagesbackground.png" "Appsloginimagesbackground.png"
==> FileSpec src=Appsloginimagesbackground.png dst=Appsloginimagesbackground.png
CopyCommand: C:TempSkypeAppsloginimagesbackground.png to Appsloginimagesbackground.png
23: "Appsloginindex.html" "Appsloginindex.html"
==> FileSpec src=Appsloginindex.html dst=Appsloginindex.html
CopyCommand: C:TempSkypeAppsloginindex.html to Appsloginindex.html
24: "Appsloginjslogin.js" "Appsloginjslogin.js"
==> FileSpec src=Appsloginjslogin.js dst=Appsloginjslogin.js
CopyCommand: C:TempSkypeAppsloginjslogin.js to Appsloginjslogin.js
25: "Appsloginlanguagesar.js" "Appsloginlanguagesar.js"
==> FileSpec src=Appsloginlanguagesar.js dst=Appsloginlanguagesar.js
CopyCommand: C:TempSkypeAppsloginlanguagesar.js to Appsloginlanguagesar.js
26: "Appsloginlanguagesvi.js" "Appsloginlanguagesvi.js"
==> FileSpec src=Appsloginlanguagesvi.js dst=Appsloginlanguagesvi.js
CopyCommand: C:TempSkypeAppsloginlanguagesvi.js to Appsloginlanguagesvi.js
27: "Appsloginlanguageszh-hans.js" "Appsloginlanguageszh-hans.js"
==> FileSpec src=Appsloginlanguageszh-hans.js dst=Appsloginlanguageszh-hans.js
CopyCommand: C:TempSkypeAppsloginlanguageszh-hans.js to Appsloginlanguageszh-hans.js
28: "Appsloginlanguageszh-hant.js" "Appsloginlanguageszh-hant.js"
==> FileSpec src=Appsloginlanguageszh-hant.js dst=Appsloginlanguageszh-hant.js
CopyCommand: C:TempSkypeAppsloginlanguageszh-hant.js to Appsloginlanguageszh-hant.js
29: "{4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi" "{4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi"
==> FileSpec src={4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi dst={4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi
CopyCommand: C:TempSkype{4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi to {4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi
30:
31:
32:
33: ;…                                 ; Many more files
34: ;*** <the end>                       ; That’s it
35:
PASS 2: Processing directive file(s)
————————————
1: ;*** MakeCAB Directive file
2: ;
3:
4: .Set FailOnMissingSource=On
==> Setting variable FailOnMissingSource to ‘On’
5: .Set MaxErrors=1
==> Setting variable MaxErrors to ‘1’
6: .Set UniqueFiles=Off
==> Setting variable UniqueFiles to ‘Off’
7: .Set CompressionType=LZX
==> Setting variable CompressionType to ‘LZX’
8: .Set CompressionMemory=21
==> Setting variable CompressionMemory to ’21’
9: .Set DiskDirectoryTemplate=.
==> Setting variable DiskDirectoryTemplate to ‘.’
10: .Set MaxDiskSize=2147483136                   ; File Size of
==> Setting variable MaxDiskSize to ‘2147483136’
11: .Set CabinetNameTemplate=Compressed-Skype.cab ; Name for the compressed outfile file
==> Setting variable CabinetNameTemplate to ‘Compressed-Skype.cab’
12: .Set Cabinet=On
==> Setting variable Cabinet to ‘On’
13: .Set Compress=On
==> Setting variable Compress to ‘On’
14: .Set SourceDir="C:TempSkype"
==> Setting variable SourceDir to ‘C:TempSkype’
15:
16:
17: ;** The list of files are stored, compressed, in cabinet files
18: "Appslogincsslogin.css" "Appslogincsslogin.css"
==> FileSpec src=Appslogincsslogin.css dst=Appslogincsslogin.css
  0.00% – raw=0  compressed=0
19: "Appslogincssplatformmac.css" "Appslogincssplatformmac.css"
==> FileSpec src=Appslogincssplatformmac.css dst=Appslogincssplatformmac.css
  0.00% – raw=0  compressed=0
20: "Appslogincssplatformwin.css" "Appslogincssplatformwin.css"
==> FileSpec src=Appslogincssplatformwin.css dst=Appslogincssplatformwin.css
  0.00% – raw=0  c
ompressed=0
21: "Appslogincssretinalogin.css" "Appslogincssretinalogin.css"
==> FileSpec src=Appslogincssretinalogin.css dst=Appslogincssretinalogin.css
  0.00% – raw=0  compressed=0
22: "Appsloginimagesbackground.png" "Appsloginimagesbackground.png"
==> FileSpec src=Appsloginimagesbackground.png dst=Appsloginimagesbackground.png
  0.00% – raw=0  compressed=0
  0.16% – raw=32,768  compressed=0
23: "Appsloginindex.html" "Appsloginindex.html"
==> FileSpec src=Appsloginindex.html dst=Appsloginindex.html
  0.16% – raw=32,768  compressed=0
24: "Appsloginjslogin.js" "Appsloginjslogin.js"
==> FileSpec src=Appsloginjslogin.js dst=Appsloginjslogin.js
  0.16% – raw=32,768  compressed=0
  0.31% – raw=65,536  compressed=0
  0.47% – raw=98,304  compressed=0
  0.63% – raw=131,072  compressed=0
  0.79% – raw=163,840  compressed=0
  0.94% – raw=196,608  compressed=0
25: "Appsloginlanguagesar.js" "Appsloginlanguagesar.js"
==> FileSpec src=Appsloginlanguagesar.js dst=Appsloginlanguagesar.js
  0.94% – raw=196,608  compressed=0
  1.10% – raw=229,376  compressed=0
26: "Appsloginlanguagesvi.js" "Appsloginlanguagesvi.js"
==> FileSpec src=Appsloginlanguagesvi.js dst=Appsloginlanguagesvi.js
  1.10% – raw=229,376  compressed=0
27: "Appsloginlanguageszh-hans.js" "Appsloginlanguageszh-hans.js"
==> FileSpec src=Appsloginlanguageszh-hans.js dst=Appsloginlanguageszh-hans.js
  1.10% – raw=229,376  compressed=0
  1.26% – raw=262,144  compressed=0
28: "Appsloginlanguageszh-hant.js" "Appsloginlanguageszh-hant.js"
==> FileSpec src=Appsloginlanguageszh-hant.js dst=Appsloginlanguageszh-hant.js
  1.26% – raw=262,144  compressed=0
29: "{4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi" "{4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi"
==> FileSpec src={4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi dst={4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi
  1.26% – raw=262,144  compressed=0
  1.41% – raw=294,912  compressed=0
  1.57% – raw=327,680  compressed=0
  1.57% – raw=327,680  compressed=10,856
  1.57% – raw=327,680  compressed=23,960
22.14% – raw=4,620,288  compressed=3,834,893

57.94% – raw=12,091,392  compressed=11,340,637

99.71% – raw=20,807,680  compressed=19,306,008
99.86% – raw=20,840,448  compressed=19,306,008
30:
31:
32:
33: ;…                                 ; Many more files
34: ;*** <the end>                       ; That’s it
35:
100.00% – raw=20,868,956  compressed=19,306,008
100.00% – raw=20,868,956  compressed=19,312,972
100.00% – raw=20,868,956  compressed=19,318,654
100.00% – raw=20,868,956  compressed=19,324,494
100.00% – raw=20,868,956  compressed=19,329,374
100.00% – raw=20,868,956  compressed=19,336,142
100.00% – raw=20,868,956  compressed=19,343,014
100.00% – raw=20,868,956  compressed=19,350,424
100.00% – raw=20,868,956  compressed=19,358,864
100.00% – raw=20,868,956  compressed=19,365,480
  0.00% [flushing current folder]
  0.06% [flushing current folder]
  0.12% [flushing current folder]
  0.18% [flushing current folder]
  0.23% [flushing current folder]
  0.28% [flushing current folder]
99.78% [flushing current folder]
99.82% [flushing current folder]
99.85% [flushing current folder]
99.89% [flushing current folder]
99.94% [flushing current folder]
99.97% [flushing current folder]
** Appslogincsslogin.css placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appslogincssplatformmac.css placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appslogincssplatformwin.css placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appslogincssretinalogin.css placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appsloginimagesbackground.png placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appsloginindex.html placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appsloginjslogin.js placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appsloginlanguagesar.js placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appsloginlanguagesvi.js placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appsloginlanguageszh-hans.js placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** Appsloginlanguageszh-hant.js placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
** {4E76FF7E-AEBA-4C87-B788-CD47E5425B9D}Skype.msi placed in cabinet Compressed-Skype.cab(1) on disk Disk 1
  0.00% [flushing current folder]
  0.17% [flushing current folder]
  0.34% [flushing current folder]
  0.51% [flushing current folder]
  1.69% [flushing current folder]

59.72% [flushing current folder]
59.89% [flushing current folder]
60.05% [flushing current folder]
60.22% [flushing current folder]
60.39% [flushing current folder]
60.56% [flushing current folder]
60.73% [flushing current folder]
60.90% [flushing current folder]

99.47% [flushing current folder]
99.64% [flushing current folder]
99.81% [flushing current folder]
99.98% [flushing current folder]
100.00% [flushing current folder]
Total files:             12     
Bytes before:    20,868,956
Bytes after:     19,365,480
After/Before:            92.80% compression
Time:                    16.33 seconds ( 0 hr  0 min 16.33 sec)
Throughput:            1247.92 Kb/second

Leave a Reply

Your email address will not be published. Required fields are marked *