Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Avoiding an error on empty directory
Message
From
18/03/2010 02:05:31
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Avoiding an error on empty directory
Environment versions
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01455295
Message ID:
01455295
Views:
81
This method compresses an entire directory structure into a .ZIP file. The only problem with that code is whenever there is an empty directory, this generates an error:
        ' Zip an entire directory
        Public Function ZipDirectory() As Boolean
            Dim llSuccess As Boolean = False
            Dim loByte(21) As Byte
            Dim loDestinationFolder As Shell32.Folder
            Dim loFolderItems As Shell32.FolderItems
            Dim loShellClass As Shell32.ShellClass = New Shell32.ShellClass
            Dim loSourceFolder As Shell32.Folder

            ' Reset everything
            lError = False
            cError = ""

            Try
                loByte(0) = 80 : loByte(1) = 75 : loByte(2) = 5 : loByte(3) = 6

                ' Make an empty PKZip file
                File.WriteAllBytes(cDestinationFile, loByte)

                loSourceFolder = loShellClass.NameSpace(cSourceFolder)
                loDestinationFolder = loShellClass.NameSpace(cDestinationFile)
                loFolderItems = loSourceFolder.Items
                loDestinationFolder.CopyHere(loFolderItems, 20)

                llSuccess = True
            Catch loError As Exception
                lError = True
                cError = loError.Message
            End Try

            Return llSuccess
        End Function
The Shell classes seems to be quite sensitive about that. Anyone have found a workaround for that?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Reply
Map
View

Click here to load this message in the networking platform