Code Examples
  Home arrow Code Examples arrow Implementing the CompressedFolder Class
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Implementing the CompressedFolder Class
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-03-19

    Table of Contents:
  • Implementing the CompressedFolder Class
  • More internal methods
  • Examining the Support Methods
  • Wrapping up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Implementing the CompressedFolder Class


    (Page 1 of 4 )

    In today’s article I’ll be continuing my explanation of the custom CompressedFolder class that we created. We’ve already discussed all of the properties and methods that have been publicly exposed through the class’s object. Now we’ll look at the rest of the methods involved, as well as how to implement the class in your own scripts.

    If you need to download the code for this series again, you can find the latest version here.

    Moving right along, we come to the second group of methods in this class.  These are the internal methods that are mirrored by the exposed methods.  As I mentioned previously, I like to keep my exposed methods very simple by pointing them to hidden methods that are only used internally by my class.  This provides me with a sort of interface between the class user and the code itself.

    Private Sub NewCompressedFolder(strPath)

       Const adTypeBinary = 1

       Const adTypeText = 2

       Const adWriteChar = 0

       Const adSaveCreateNotExist = 1

       Const adSaveCreateOverwrite = 2

     

       With CreateObject("ADODB.Stream")

           .Open

           .Type = adTypeText

           .WriteText ChrB(&h50) & ChrB(&h4B) & ChrB(&h5) & ChrB(&h6)

           For i = 1 To 18

              .WriteText ChrB(&h0)

           Next

           .SaveToFile strPath, adSaveCreateNotExist

           .Close

           .Open

           .Type = adTypeBinary

           .LoadFromFile strPath

           .Position = 2

           arrBytes = .Read

           .Position = 0

           .SetEOS

           .Write arrBytes

           .SaveToFile strPath, adSaveCreateOverwrite

           .Close

       End With

    End Sub

    The exposed Open method points to the NewCompressedFolder method for creating new compressed folders.  My dedicated readers will recognize this code.  Basically, I’m exploiting the ADODB Stream object and forcing it to write a binary file.  I predetermined the binary string necessary to create a compressed file by examining an empty one with a hex editor.  If you really want to understand this portion of code, you should take the time to read my article “Compressed Folders in WSH.”

    You should note that this method does not parse the provided string before attempting to use it.  This is mostly for lack of space.  If you were to implement this code or distribute it, it really should have some proper error-handling.  Sending a malformed path to the ADODB Stream object will provide some extremely strange results.

    Private Function AddFile(strFolder, strFile, blnKeepOriginal)

       Set objFolder = objShell.NameSpace(strFolder)

       intCount = objFolder.Items.Count

       Select Case CBool(blnKeepOriginal)

           Case True

              objFolder.CopyHere strFile, 1548

           Case False

              objFolder.MoveHere strFile, 1548

       End Select

       Do Until objFolder.Items.Count = intCount + 1

           Sleep 200

           If Not ShellBusy Then Exit Do

       Loop

    End Function

    The AddFile method is used to add a file to the compressed folder.  I’ve taken advantage of the Shell Object’s ability to handle compressed folders natively by basically masking calls to the MoveHere and CopyHere methods.  Since these procedures are performed synchronously, I’ve added a little timer loop to pause execution until the process completes.  This provides some means of monitoring the process completion.  (As a part of this, I created the ShellBusy subroutine that you’ll see later.)

    Here again, I’m assuming that the provided file name is correct.  In a production environment, proper handling should be included to verify that the provided parameter is correct before attempting to move or copy that file into the compressed folder.

    More Code Examples Articles
    More By Nilpo


     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek