Sample code for 30+ languages & platforms
PowerBuilder

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:

  • bin directories
  • obj directories
  • .vs directories
  • *.exe, *.dll, *.pdb, and related output files
  • Temporary and cache files

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Zip
oleobject loo_SaExcludes
integer li_Recurse

li_Success = 0

loo_Zip = create oleobject
li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip")
if li_rc < 0 then
    destroy loo_Zip
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Create a new, empty Zip object.
// The .zip file is not created until WriteZip or WriteZipAndClose is called.
li_Success = loo_Zip.NewZip("VisualStudioProject.zip")
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    return
end if

// 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
// 
loo_Zip.PathPrefix = "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.
loo_Zip.ExcludeDir("bin")
loo_Zip.ExcludeDir("obj")
loo_Zip.ExcludeDir(".vs")
loo_Zip.ExcludeDir("packages")

// ------------------------------------------------------------
// Create a StringArray containing wildcard exclusion patterns
// for generated files and temporary artifacts.
loo_SaExcludes = create oleobject
li_rc = loo_SaExcludes.ConnectToNewObject("Chilkat.StringArray")

// Exclude common compiled output files.
loo_SaExcludes.Append("*.exe")
loo_SaExcludes.Append("*.dll")
loo_SaExcludes.Append("*.pdb")
loo_SaExcludes.Append("*.ilk")
loo_SaExcludes.Append("*.lib")
loo_SaExcludes.Append("*.obj")

// Exclude NuGet package files.
loo_SaExcludes.Append("*.nupkg")

// Exclude temporary, cache, and user-specific files.
loo_SaExcludes.Append("*.cache")
loo_SaExcludes.Append("*.tmp")
loo_SaExcludes.Append("*.user")
loo_SaExcludes.Append("*.suo")
loo_SaExcludes.Append("*.log")

// Apply the wildcard exclusion patterns to the Zip object.
loo_Zip.SetExclusions(loo_SaExcludes)

// ------------------------------------------------------------
// 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.
li_Recurse = 1

li_Success = loo_Zip.AppendFiles("c:/projects/MyProject/*",li_Recurse)
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    destroy loo_SaExcludes
    return
end if

// ------------------------------------------------------------
// 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.
li_Success = loo_Zip.WriteZipAndClose()
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Zip
    destroy loo_SaExcludes
    return
end if

Write-Debug "Visual Studio project ZIP created successfully."


destroy loo_Zip
destroy loo_SaExcludes