ExpandFile Function  
 
BOOL WINAPI ExpandFile(
  LPCTSTR lpszInputFile,  
  LPCTSTR lpszOutputFile  
);

The ExpandFile function expands the contents of a previously compressed file.

Parameters

lpszInputFile
A null-terminated string which specifies the name of the file to be compressed. The file must exist, and it must be a regular file that can be opened for reading by the current process. An error will be returned if a character device, such as CON: is specified as the file name. An error will be returned if this parameter is NULL or a zero-length string.
lpszOutputFile
The name of the file that is to contain the expanded file data. If the file exists, it must be a regular file that can be opened for writing by the current process and will be overwritten. If the file does not exist, it will be created. An error will be returned if a character device, such as CON: is specified as the file name. If this parameter is NULL or a zero-length string, the compression is performed in-place.

Return Value

A non-zero value is returned if the file was successfully expanded. A zero value indicates that the input file could not be read or that the output file could not be created.

Remarks

The ExpandFile function can only expand files that were previously compressed using the CompressFile function. It cannot expand the contents of a file stored in an archive format used by third-party applications such as PKZip or WinZip.

This function will use the default Deflate algorithm to expand the contents of the file. If the file was compressed using CompressFileEx using anything other than COMPRESSION_TYPE_DEFLATE, the file must be expanded using the ExpandFileEx function. This function will fail if a different compression algorithm was used to compress the file.

If the output file already exists, it will be replaced with the expanded contents of the compressed input file. If the input file cannot be expanded for any reason, the output file will be deleted and the last error code will be updated indicating the cause of the failure. If you want to ensure an existing output file will be preserved if an error occurs, you should create a temporary file and use it as the output file. If this function succeeds, then you can rename or move the temporary file using a function like MoveFileEx.

It is possible to expand the input file in-place by specifying the lpszOutputFile parameter as a NULL pointer or zero-length string. In this case, the contents of the input file will be expanded to a temporary file and if the operation is successful, the original compressed input file will be replaced by the temporary file. If an error occurs, the input file will remain unchanged.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: csncdv11.lib
Unicode: Implemented as Unicode and ANSI versions

See Also

CompressFile, CompressFileEx, DecodeFile, EncodeFile, ExpandFileEx