1

I see there is a nice way in this post

How can I compress (/ zip ) and uncompress (/ unzip ) files and folders with batch file without using any external tools?

to zip the folder using makecab. One problem with the above script is it can't handle long file name (with long extension name). Fox example, if I have a file with file name, somelongfilename.extension, after I zip and unzip, the filename will be SOMELO~1.EXT. Can anybody direct me a way to fix it?

Community
  • 1
  • 1
NickOSU
  • 65
  • 2
  • 8
  • PS. I am a newbie on stackoverflow and can't add a comment on the above post. Can somebody help me do that? – NickOSU Feb 26 '17 at 20:09

1 Answers1

0

I've done similar thing lately. But I use an external tool called DDFGenerator. It's free and small, and it handles long file name properly.

To compress structured folders and files with makecab.exe, a DDF file is a must. Instead of using the batch script mentioned in the answer you quoted, I used DDFGenerator for the same goal.

DDFGenerator on CodePlex

Say, the folder you want to "zip" locates at C:\MyFolder\MyData , use this command to generate a DDF file named "solution.ddf" at C:\MyFolder:

DDFGenerator "C:\MyFolder"

Note that DDFGenerator.exe iterate files "under" the folder you provides, so to compress C:\MyFolder\MyData, you should pass "C:\MyFolder" to it and make sure MyData is the only item in C:\MyFolder.

After the solution.ddf has been generated, a small tweak is necessary. Just open the "solution.ddf" with any text editor you prefer and make these changes:

Replace these 2 lines (at the very beginning):

.Set DiskDirectoryTemplate=CDROM
.Set CompressionType=MSZIP

To be:

.Set CabinetName1={YourCabName}.cab
.Set CompressionType=LZX
.Set CabinetFileCountThreshold=0
.Set FolderFileCountThreshold=0
.Set FolderSizeThreshold=0
.Set MaxCabinetSize=0
.Set MaxDiskFileCount=0
.Set MaxDiskSize=0

(Replace {YourCabName} to whatever suit your needs) These changes ensure no splitting and with better compression ratio.

Then, run the makecab command at C:\MyFolder to build the cab:

makecab.exe /F solution.ddf

The {YourCabName}.cab will be located under C:\MyFolder\disk1 after done. Just take it and delete other files that have been generated.

To "unzip" the cab at current path, use command:

expand {YourCabName}.cab /F:* .
zevoid
  • 171
  • 1
  • 7