Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Avoiding an error on empty directory
Message
De
18/03/2010 02:05:31
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Avoiding an error on empty directory
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01455295
Message ID:
01455295
Vues:
82
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
Répondre
Fil
Voir

Click here to load this message in the networking platform