![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Swift) ZIP a Visual Studio Project and Exclude Build ArtifactsSee more Zip ExamplesThis 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:
func chilkatTest() { var success: Bool = false let zip = CkoZip()! // Create a new, empty Zip object. // The .zip file is not created until WriteZip or WriteZipAndClose is called. success = zip.newZip("VisualStudioProject.zip") if success == false { print("\(zip.lastErrorText!)") return } // 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 // 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. zip.excludeDir("bin") zip.excludeDir("obj") zip.excludeDir(".vs") zip.excludeDir("packages") // ------------------------------------------------------------ // Create a StringArray containing wildcard exclusion patterns // for generated files and temporary artifacts. let saExcludes = CkoStringArray()! // Exclude common compiled output files. saExcludes.append("*.exe") saExcludes.append("*.dll") saExcludes.append("*.pdb") saExcludes.append("*.ilk") saExcludes.append("*.lib") saExcludes.append("*.obj") // Exclude NuGet package files. saExcludes.append("*.nupkg") // Exclude temporary, cache, and user-specific files. saExcludes.append("*.cache") saExcludes.append("*.tmp") saExcludes.append("*.user") saExcludes.append("*.suo") saExcludes.append("*.log") // Apply the wildcard exclusion patterns to the Zip object. zip.setExclusions(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. var recurse: Bool = true success = zip.appendFiles("c:/projects/MyProject/*", recurse: recurse) if success == false { print("\(zip.lastErrorText!)") return } // ------------------------------------------------------------ // 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. success = zip.writeAndClose() if success == false { print("\(zip.lastErrorText!)") return } print("Visual Studio project ZIP created successfully.") } |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.