DataFlex
DataFlex
ZIP a Visual Studio Project and Exclude Build Artifacts
See more Zip Examples
This example demonstrates how to create a ZIP archive of a Visual Studio project directory while excluding files and directories commonly created during builds.
This is useful when archiving or sharing source code without including compiled binaries, intermediate build output, debug symbols, cache files, or generated package folders.
The example excludes common Visual Studio build artifacts such as:
bindirectoriesobjdirectories.vsdirectories*.exe,*.dll,*.pdb, and related output files- Temporary and cache files
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoZip
Variant vSaExcludes
Handle hoSaExcludes
Boolean iRecurse
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatZip)) To hoZip
If (Not(IsComObjectCreated(hoZip))) Begin
Send CreateComObject of hoZip
End
// Create a new, empty Zip object.
// The .zip file is not created until WriteZip or WriteZipAndClose is called.
Get ComNewZip Of hoZip "VisualStudioProject.zip" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
// When the ZIP is extracted, all files will be placed beneath
// the "MyProject/" directory.
//
// For example:
//
// src/main.cpp
//
// Will be stored in the ZIP as:
//
// MyProject/src/main.cpp
//
Set ComPathPrefix Of hoZip To "MyProject/"
// We will add files from this Visual Studio project directory:
//
// c:/projects/MyProject
//
// The goal is to ZIP the source project without the files generated
// by Visual Studio builds.
// ------------------------------------------------------------
// Exclude directories commonly created by Visual Studio builds.
//
// Any directory having one of these names will be skipped entirely,
// including all files and subdirectories beneath it.
Send ComExcludeDir To hoZip "bin"
Send ComExcludeDir To hoZip "obj"
Send ComExcludeDir To hoZip ".vs"
Send ComExcludeDir To hoZip "packages"
// ------------------------------------------------------------
// Create a StringArray containing wildcard exclusion patterns
// for generated files and temporary artifacts.
Get Create (RefClass(cComCkStringArray)) To hoSaExcludes
If (Not(IsComObjectCreated(hoSaExcludes))) Begin
Send CreateComObject of hoSaExcludes
End
// Exclude common compiled output files.
Get ComAppend Of hoSaExcludes "*.exe" To iSuccess
Get ComAppend Of hoSaExcludes "*.dll" To iSuccess
Get ComAppend Of hoSaExcludes "*.pdb" To iSuccess
Get ComAppend Of hoSaExcludes "*.ilk" To iSuccess
Get ComAppend Of hoSaExcludes "*.lib" To iSuccess
Get ComAppend Of hoSaExcludes "*.obj" To iSuccess
// Exclude NuGet package files.
Get ComAppend Of hoSaExcludes "*.nupkg" To iSuccess
// Exclude temporary, cache, and user-specific files.
Get ComAppend Of hoSaExcludes "*.cache" To iSuccess
Get ComAppend Of hoSaExcludes "*.tmp" To iSuccess
Get ComAppend Of hoSaExcludes "*.user" To iSuccess
Get ComAppend Of hoSaExcludes "*.suo" To iSuccess
Get ComAppend Of hoSaExcludes "*.log" To iSuccess
// Apply the wildcard exclusion patterns to the Zip object.
Get pvComObject of hoSaExcludes to vSaExcludes
Send ComSetExclusions To hoZip vSaExcludes
// ------------------------------------------------------------
// Recursively add references to the project files.
//
// AppendFiles does not immediately read or compress the files.
// It adds file references to the Zip object. The referenced files
// are read and compressed later when WriteZipAndClose is called.
Move True To iRecurse
Get ComAppendFiles Of hoZip "c:/projects/MyProject/*" iRecurse To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
// ------------------------------------------------------------
// Write the ZIP archive and close it.
//
// This is where the referenced source files are actually read,
// compressed as needed, and written to the final .zip archive.
Get ComWriteZipAndClose Of hoZip To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoZip To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Visual Studio project ZIP created successfully."
End_Procedure