MakeCAB是微軟提供的製作CAB的檔案,詳細的MakeCAB介紹請參考微軟MSDN。系統給出命令用法如下:
Microsoft (R) Cabinet Maker - Version (32) 1.00.0601 (03/18/97)
Copyright (c) Microsoft Corp 1993-1997. All rights reserved.
MAKECAB [/V[n]] [/D var=value ...] [/L dir] source [destination]
MAKECAB [/V[n]] [/D var=value ...] /F directive_file [...]
source File to compress.
destination File name to give compressed file. If omitted, the
last character of the source file name is replaced
with an underscore (_) and used as the destination.
/F directives A file with MakeCAB directives (may be repeated).
/D var=value Defines variable with specified value.
/L dir Location to place destination (default is current directory).
/V[n] Verbosity level (1..3).
如果目錄裡面有多個檔案,那麼就需要編寫一個檔案清單檔案,用來告訴MakeCAB,有多少檔案需要打包。
簡單的編寫了一個list.txt檔案,裡面僅僅包含2行。一個是libactivex.inf,一個libactivex.dll
然後執行:
makecab /F list.txt /D compressiontype=lzx /D compressionmemory=21 /V
系統將顯示壓縮過程和壓縮結果,如下:
Microsoft (R) Cabinet Maker - Version 5.1.2600.2180
Copyright (c) Microsoft Corporation. All rights reserved..
287,395 bytes in 2 files
Total files: 2
Bytes before: 287,395
Bytes after: 162,170
After/Before: 56.43% compression
Time: 0.74 seconds ( 0 hr 0 min 0.74 sec)
Throughput: 378.76 Kb/second
壓縮之後,目錄下將產生一個目錄,將目錄裡面的檔案改名成libactivex.cab(可以是你需要的檔案名稱)就OK了。
然後就可以放到WEB伺服器的目錄下,IE開啟的時候就會提示下載了。
附:INF的產生方法將在以後介紹。
其實,還有2個辦法產生CAB檔案,一個就是利用Visual Studio,另外一個就是利用專門的打包工具,可以google一下。
makecab 的使用方法詳解與技巧 :
最簡單的用法:
makecab 檔案完整的名稱 如 makecab wmd.dll
指定壓縮類型及使用記憶體的大小:
makecab /d compressiontype=lzx /d compressionmemory=21 wmd.dll 壓縮比高
批量壓縮的辦法:
for %v in (*.*) do makecab %v
之前俺研究了好久,都不知道怎麼用一條命令將一個目錄下的所有檔案壓縮成CAB包,現在終於知道了,壓縮成一個CAB包的辦法:
makecab /f list.txt /d compressiontype=mszip /d compressionmemory=21 /d maxdisksize=1024000000 /d diskdirectorytemplate=dd* /d cabinetnametemplate=dd*.cab
來個高壓縮比的:
makecab /f list.txt /d compressiontype=lzx /d compressionmemory=21 /d maxdisksize=1024000000 /d diskdirectorytemplate=dd* /d cabinetnametemplate=dd*.cab