Manipulating Zip files and other archives

Built into ActiveFile is a fully functioning archive engine that be used to create and manipulate ZIP, TAR, and Stuff-IT archives.

Upload Topics

Creating an archive on the fly
Extracting the contents of an archive
Copying, renaming and deleting an archive

 

 

   Creating an archive on the fly

Using the Archive object, you can create an archive and add any number of arbitrary files to the archive. The example below demonstrates how to create a ZIP archive on the fly and download it to the browser.

<%
    ' Create a temp file to hold the archive
    Set File = Server.CreateObject("ActiveFile.File")
    File.CreateTemp "C:\TEMP"

    ' Create the ZIP archive
    Set Archive = Server.CreateObject("ActiveFile.Archive")
    Archive.NewArchive File, 0

    ' Add some files to the ZIP archive
    Archive.Add "C:\My Documents\*.*"

    ' Save and release the ZIP archive
    Archive.SaveArchive
    Set Archive = Nothing

    ' Download and delete the ZIP archive
    Response.AddHeader "Content-Disposition", "inline; filename=foo.zip"
    File.Download "application/x-zip-compressed", Now(), True, True
%>

 

 

   Extracting the contents of an archive

If you have an existing archive on your server, you can display the names and sizes of the archived files and extract them to a local or network drive. The example below produces a listing of the contents of a ZIP archive:

<%
    ' Load an existing archive
    Set Archive = Server.CreateObject("ActiveFile.Archive")
    Archive.OpenArchive "C:\myarch.zip"

    ' Display contents
    For Each Entry In Archive.Entries
        Response.Write Entry.Path & "<BR>"
    Next
%>

The following example extracts a single file from the archive and downloads it to the browser:

<%
    ' Create a temp directory to hold the archive contents
    Set Directory = Server.CreateObject("ActiveFile.Directory")
    Directory.CreateTemp "C:\TEMP"

    ' Open an existing archive
    Set Archive = Server.CreateObject("ActiveFile.Archive")
    Archive.OpenArchive "C:\myarch.zip"

    ' Extract a file in the archive
    Archive.Extract Directory & "myfile.gif"

    ' Download and clean up
    File.Download Directory & "myfile.gif"
    Directory.Delete True
%>

 

 

   Copying, renaming and deleting an archive

Because archives are simply files stored in the file system, the ActiveFile File object can be used to copy, rename, and delete archives. For more information on manipulating files see Manipulating files and directories.

 

File Upload File Download File Upload File Download File Upload File Download File Upload File Download File Upload File Download File Upload File Download ASP .NET Drag n Drop Java Mac OS X