Creating and Using Cabinet Files for Java Applets and Libraries |
![]() Previous |
![]() About Tools |
![]() Next |
Cabinets are created using the n command, followed by the name of the cabinet to create, followed by a file name list. This is shown in the following example:
cabarc n mycab.cab prog.c prog.h prog.exe readme.txt
The previous command creates the cabinet Mycab.cab containing the files Prog.c, Prog.h, Prog.exe, and Readme.txt, in a single folder, using the default compression mode, MSZIP.
Cabarc is used as follows:
cabarc [<options>] <command> [<file list>]
Three commands are currently supported: n (create new cabinet), l (list contents of an existing cabinet), and x (extract files from a cabinet). These commands are described later in this document.
Cabarc supports wildcards in the filename list, as shown in the example below:
cabarc n mycab.cab prog.* readme.txt
All files are added to a single folder (compression history) in the cabinet. It is possible to instruct cabarc to begin a new folder by using the plus sign (+) for the file to be added, as shown in the following example:
cabarc n mycab.cab test.c main.c + test.exe *.obj
The above command creates the cabinet mycab.cab with one folder containing test.c and main.c, and a second folder containing test.exe and all files matching *.obj.
By default, directory names are not preserved in the cabinet, only the filename component is stored. For example, the following command stores prog.c in the cabinet:
cabarc n mycab.cab c:\source\myproj\prog.c
To preserve path names, use the -p option as shown in the following example:
cabarc -p n mycab.cab c:\mysource\myproj\prog.c
This command puts mysource\myproj\prog.c in the cabinet. Be aware that the c:\ prefix is still stripped from the filename; Cabarc will not allow absolute paths to be stored in the cabinet, nor will it extract such absolute paths.
Path stripping is an option, -P, for preserving part (but not all) of a path name. The following example shows how the path stripping option can archive everything in the c:\mysource\myproj\ directory, but store only the myproj\ component of the path.
cabarc -p -P mysource\ n mycab.cab c:\mysource\myproj\prog.c
The -P option strips any strings that begin with the provided string. Be aware that wildcards are not supported by the -P option; it is a simple text match. Absolute path prefixes, such as c:\ or \, are stripped before the comparison takes place. Do not include absolute path prefixes when using the -P option.
The -P option may be used multiple times to strip out multiple paths. Cabarc builds a list of all paths to be stripped and applies only the first one that matches. Consider the following example:
cabarc -p -P mysrc\ -P yoursrc\ n mycab.cab c:\mysrc\myproj\*.* d:\yoursrc\yourproj\*.c
The trailing slash at the end of the path name is important: Entering -P mysrc instead of -P mysrc\ would cause files to be added as \myproj\<filename>.
Cabarc can archive files in a directory and all of its subdirectories, by use of the -r option. For example, the following command example archives all files ending in .h that are in c:\msdev\include\, c:\msdev\include\sys, and c:\msdev\include\gl (assuming these directories exist on your system).
cabarc -r -p n mycab.cab c:\msdev\include\*.h
The -p option is used here to preserve the path information when the files are added to the cabinet. Without this option, only the filename components would be stored, although sometimes it might be desirable behavior to not use -p.
Cabarc can reserve space in the cabinet for a code signature. This is done with the -s option, which reserves a specified amount of empty space in the cabinet. For code signatures, reserve 6144 bytes. Consider the following example for doing so:
cabarc -s 6144 n mycab.cab test.exe
Be aware that the -s option does not actually write the code signature; it merely reserves space for it in the cabinet. Use the appropriate code signing utility to fill out the code signature.
Cabinet files have a 16-bit cabinet ID field that is designed for application use. The default value of this field is zero; however, use the -i option of cabarc to set this field to any 16-bit value. Consider the following example:
cabarc -i 12345 n mycab.cab test.exe
Set the compression type with the -m option. The default compression type for a cabinet is MSZIP . Only MSZIP compression (-m MSZIP) and no compression (-m NONE) are currently supported. The following command stores files in the cabinet without compression:
cabarc -m NONE n mycab.c *.*
Cabarc can input its list of files from a text file, instead of from the command line, using the @file option followed by the name of the file from which to take the inputs. Consider the following example:
cabarc n mycab.cab @file filelist.txt
The text file must list the physical file names of the files to be added, one per line. As is the case when specifying filenames on the command line, the plus (+) symbol can be used as a filename to specify the beginning of a new folder. If a filename contains any embedded spaces, it must be enclosed as quotes, as shown below:
test.c myapp.exe "output file.exe"
Quotation marks are required because each physical filename can be followed (on the same line) by an optional logical filename, which specifies the name under which the file will be stored in the cabinet. Consider the following example:
test.c myapp.c myapp.exe "output file.exe" myfile.exe
If the logical filename contains spaces, it also must be enclosed in quotation marks. Note that the logical filename overrides the -p (preserve path names) and -P (strip path name) options; the file is added to the cabinet exactly as indicated. Wildcards can be used in the physical filename, but in this situation, a logical filename is not allowed.
The @file option can be used multiple times, to retrieve file lists from multiple files. Cabarc does not check for the presence of duplicate files, so if the same physical file appears in multiple file lists, it will be added to the cabinet multiple times.
The @file option can be combined with filenames on the command line. The files from the use of -l option are added first. Consider the following example:
cabarc -l filelist1.txt -l filelist2.txt n mycab.cab *.c *.h
Note that the @file option is available only when creating cabinets, not when extracting or listing cabinets.
It is possible to view the contents of a cabinet using the L (list) command, as shown below:
cabarc l mycab.cab
Cabarc displays the cabinet identifier in the cabinet (see the -s option for cabinet creation). Cabarc also displays the following file information: size, date, time, and attributes.
The X (extract) command extracts files from a cabinet. The simplest use of the X command is shown in the following example, which extracts all files from the cabinet:
cabarc x mycab.cab
Alternatively, it is possible to selectively extract files by providing a list of filenames and/or wildcards:
cabarc x mycab.cab readme.txt *.exe *.c
Full path names (if they are present in the cabinet) are not preserved upon extraction by default. For example, if a file named mysrc\myproj\test.c is present in the cabinet, the command cabarc x mycab.cab will cause the file test.c to be extracted into the current directory. To preserve file names upon extraction, the -p option must be used. The -p option causes any required directories to be created, if necessary.
Only the filename component is considered in the matching process. The path name is ignored. For example, the command "cabarc x mycab.cab test.c" causes the file mysrc\myproj\test.c to be extracted to the current directory as test.c, as will cabarc x mycab.cab *.c (which also extracts any other files matching *.c).
By default, the extracted files are stored in the current directory (and its subdirectories, if the -p option is used). However, it is possible to specify a destination directory for the extracted files. This is accomplished by appending a directory name to the command line. The directory name must end in a backslash ("\"). Consider the following examples:
cabarc x mycab.cab c:\somedir\ cabarc x mycab.cab *.exe c:\somedir\
![]() | © 1997 Microsoft Corporation. All rights reserved. Terms of Use. |