![]() |
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
(SQL Server) Iterate Through Matching ZIP Entries Using EntryMatching and ZipEntry.GetNextMatchSee more Zip ExamplesThis example demonstrates how to iterate through ZIP entries matching a wildcard pattern using:
The wildcard character The example searches for all entries beneath the Suppose the ZIP archive contains: The wildcard pattern: Matches: Note that ZIP archives may optionally contain separate directory entries. Therefore, the first matching entry may be the directory entry
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @success int SELECT @success = 0 DECLARE @zip int EXEC @hr = sp_OACreate 'Chilkat.Zip', @zip OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Open an existing ZIP archive. EXEC sp_OAMethod @zip, 'OpenZip', @success OUT, 'c:/temp/sample.zip' IF @success = 0 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip RETURN END -- ------------------------------------------------------------ -- Find the first ZIP entry matching the wildcard pattern: -- -- docs/* -- -- Matching is performed against the full stored ZIP path. -- DECLARE @entry int EXEC @hr = sp_OACreate 'Chilkat.ZipEntry', @entry OUT EXEC sp_OAMethod @zip, 'EntryMatching', @success OUT, 'docs/*', @entry IF @success = 0 BEGIN PRINT 'No matching entries found.' EXEC sp_OAMethod @zip, 'CloseZip', NULL EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @entry RETURN END -- ------------------------------------------------------------ -- Iterate through all matching entries. -- -- GetNextMatch updates the same ZipEntry object so that -- it represents the next matching entry. -- WHILE (@success = 1) BEGIN EXEC sp_OAGetProperty @entry, 'IsDirectory', @iTmp0 OUT IF @iTmp0 = 1 BEGIN EXEC sp_OAGetProperty @entry, 'FileName', @sTmp0 OUT PRINT '[Directory] ' + @sTmp0 END ELSE BEGIN EXEC sp_OAGetProperty @entry, 'FileName', @sTmp0 OUT PRINT '[File] ' + @sTmp0 END -- Advance to the next matching entry. EXEC sp_OAMethod @entry, 'GetNextMatch', @success OUT, 'docs/*' END EXEC sp_OAMethod @zip, 'CloseZip', NULL PRINT 'Done.' EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @entry END GO |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.