Using MakeCab.exe & .ddf file (i.e. using directive file) how to specify destination cab filename?

StackOverflow https://stackoverflow.com/questions/15843347

  •  01-04-2022
  •  | 
  •  

Question

I have decided to use makecab.exe for my requirement to create cab files in my application. http://msdn.microsoft.com/en-us/library/bb417343.aspx#microsoftmakecabusersguide

And I need to store files as per given path whether relative or absolute inside cab and extract files with original path preserved. So I will be using directive file for this and give that input to makecab command.

windows command promt zip/compress directory

But the cab output is stored in folder Disk1\1.cab.

Please help me to know how can I specify a desired cab filename as destination (I will take cab file name from user input)?

Also, is it possible to append more files to existing cab file in second run of makecab command?

Was it helpful?

Solution

Finally found the solution.

You can set following two variables in the directive file which will identify destination path and name of cab file:

DiskDirectoryTemplate=template [Output directory name template; * is replaced by disk number]
CabinetNameTemplate=template [Cabinet file name template; * is replaced by Cabinet number]

Description from Microsoft MakeCAB User's Guide

DiskDirectoryTemplate=template

Set the output directory name template. One directory is created for each disk of the layout.

Default: .Set DiskDirectoryTemplate=DISK* ; Default is DISK1, DISK2, etc.

As MakeCAB processes a directive file, it will create one or more disk "images". Rather than using some specific disk format, however, MakeCAB simply creates one subdirectory for each disk and places the files for each disk in the appropriate directory. If a * exists in this variable, then it is replaced with the disk number. If no * is specified, then all files are placed in the single directory specified by this variable.

This variable is used only if no variable DiskDirectoryn exists for disk n.

Examples:

.Set DiskDirectoryTemplate=C:\EXCEL6\DISK*  ; Put files in separate dirs
.Set DiskDirectoryTemplate=C:\EXCEL6        ; Put all files in C:\EXCEL6
.Set DiskDirectoryTemplate=                 ; Put all files in current dir

CabinetNameTemplate=template

Sets the cabinet file name template.

Default: .Set CabinetNameTemplate=*.CAB ; 1.CAB, 2.CAB, ...

This template is used to construct the file name of each cabinet. The * in this template is replaced by the cabinet number (1, 2, etc.). This variable is used only if no variable CabinetNamen exists for cabinet n.

NOTE: Be sure that the expanded cabinet name does not exceed the limits for your file system! For example, if you used "CABINET*.CAB", and MakeCAB had to create 10 or more cabinets, then you would have cabinet names like CABINET10.CAB, which is 9.3, which is an invalid name in the FAT file system. Unfortunately, MakeCAB would not detect this until it had already created 9 cabinets!

Examples:

.Set CabinetNameTemplate=EXCEL*.DIA  ; EXCEL1.DIA, EXCEL2.DIA, etc.

.Set CabinetNameTemplate=*.          ; 1, 2, 3, etc.

In addition, when files are split across cab (in case if cabinet size exceeds its limit size) then you can set subsequent cabinet filenames also using variable CabinetNamen:

CabinetNamen=filename [Cabinet file name for cabinet number n]

CabinetNamen=filename

The cabinet file name for the specified cabinet.

Default: ; By default none of these variables are defined

If this variable is not defined for a particular disk, then MakeCAB uses the CabinetNameTemplate to construct the cabinet name.

Example:

.Set CabinetName2=test2.cab

OTHER TIPS

If you know exactly where your source files exist, you can generate a file list from the directory:

dir C:\FolderName /s /b /a-d > c:\temp\files.txt

Then use the files.txt file to create the cab file.

makecab /d CabinetName1=test.cab /D DiskDirectoryTemplate=C:\temp /f c:\temp\files.txt

The above command will generate a test.cab file in your C:\Temp folder using the file list generated earlier.

Additional helpful reference: Microsoft Cabinet Reference. and makecab.exe details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top