I would like to make a .cab file of multiple files. Any tutorial or guide I've come across is only useful for a few files.
According to Wikipedia:
The CAB file format may employ the following compression algorithms:
- DEFLATE – invented by Phil Katz, the author of the ZIP file format
- Quantum compression – licensed from David Stafford, the author of the Quantum archiver
- LZX – invented by Jonathan Forbes and Tomi Poutanen, given to Microsoft when Forbes joined the company
As such, any .zip compressor should open the file, even the one that's native with all recent Windows versions.
However, and as the article indicates, there are few archivers that create .cab files, due to their format. According to the following list these programs can write .cab files:
You can use the Windows built-in command
makecab but first you need to generate a file list.
dir C:\FolderName /s /b /a-d > c:\temp\files.txt
This will list all files in the C:\FolderName directory and save as a text file with full path name. Now we are going to 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.
"A single CAB file can be used to store a maximum of 65,535 files with a total size of up to 1.99 GiB. To compress multiple files into a single CAB file, use a directive file containing a list of the files to compress and package."
Directive file (list.txt):
.Set CabinetNameTemplate=Out.cab; .Set Cabinet=on; .Set Compress=off; .Set DiskDirectoryTemplate=; file1 file2 file3 .etc
Optionally, set compress to on (to save space), then enter command in cmd:
makecab /f list.txt
To create a self extracting archive:
copy /b "%windir%\system32\extrac32.exe"+"Out.cab" CABfiles.exe
Tested on Win 10 CMD.
Do you need to update or regenerate a CAB file, maybe replace a single file in an existing CAB while preserving the folder structure in the CAB? That's what I needed to do. Quick research revealed no simple 7Zip or WinZip way to update an existing CAB in place. I found a success path via regenerating a new CAB file, just like the old CAB file, except with my handful of modified files in it.
The tool that does this is a GUI front end to the MakeCab utility. MakeCab, with the right command line, will create a CAB file from all files in a folder.
Get MakeCab here: https://github.com/sapientcoder/CabMaker
The workflow to create an updated CAB file is:
- Open a Command Line, and use the Expand command to extract the files from the existing CAB file to a folder structure.
expand -F:* \MyServer\ServerMigration2020\ExportedConfigurationSourceFiles\MyOriginalCABFile.cab \MyServer\CaptureSV\ServerMigration2020\Cabfiles\CabSourceFiles
This Expand command extracts all the files inside your original CAB file and places them in the folder CabSourceFiles, preserving the folder structure.
Make whatever updates you want to the extracted files and folders. In my case, there was one file, an XML file, I replaced within the folder structure.
Run the CabMaker GUI to create your updated CAB file. Note that this works for a "plain" CAB file of just files and folders, not an "installer" CAB file that has extra headers and such as part of a set of installer files.
OK, how to obtain and use the CabMaker tool?
Get it here: https://github.com/sapientcoder/CabMaker I simply downloaded the CabMaker C# code from GitHub and ran it in Visual Studio 2019, with no changes.
The CabMaker GUI came right up. I entered my Source folder (the output folder in the Expand command), and my Target folder (where the resulting CAB file gets placed), and my desired CAB file name, and clicked the "Make CAB" button, and it ran. The resulting CAB file worked beautifully, and imported successfully into the app and resulted in a correctly set configuration.
OK, so why did I need to make a CAB file? Well, we were migrating a vendor app from an old server to a new server, and using the app's "export" function to capture current state configuration files that we could "import" into the app on the new server. the alternative was to use the clunky GUI of the consumer app to manually navigate around and make a couple hundred changes to file and folder names that had changed. I decided it would be better to make the file and folder changes in the XML file within the CAB that held all the settings. It all worked out beautifully on server cutover day; sometimes we get lucky. Major kudos to GitHub contributor SapientCoder!