Archive Object Classic ASP

The File Transfer CS  Archive object represents a file that contains one or more embedded files. Depending on the archive type it may also contain directory/folder information and may be capable of compressing the files.

Collections  Entries (default property)

Properties  ArchiveType, Password, TempDir

Methods  Add, CloseArchive, Delete, Extract, NewArchive, OpenArchive, SaveArchive

 

 

  Collections

Entries

Collection of ArchiveEntry objects that are in the Archive

Access: Read
Default: None

Notes: The collection is not available until either the OpenArchive or NewArchive method is called.

Because this is the default property the following are equivalent:

Set Entries = Archive.Entries
Set Entries = Archive

Example: The following example shows how to display the contents of an archive:

Set Archive = Server.CreateObject("File Transfer CS .Archive")
Archive.OpenArchive "foo.zip"
For Each Entry In Archive
    Response.Write Entry.Path & "<BR>"
Next

See Also: ArchiveEntry object, Archive.OpenArchive method, Archive.NewArchive method

 

 

  Properties

ArchiveType

A long indicating the type of the archive currently open

Access: Read

Notes: This property represents the format of the archive as defined in the table below.

Constant Value Description
AF_ARCHIVE_ZIP 0 Zip archive format popular on many platforms including Windows systems
AF_ARCHIVE_STUFFIT 20 Stuffit archive format popular on Macintosh systems
AF_ARCHIVE_TAR 21 TAR archive format popular on Unix systems
AF_ARCHIVE_GZIP 10 GNU zip format popular on many systems
AF_ARCHIVE_MACBIN 12 MacBinary format popular on Macintosh systems

The value is not available until either the OpenArchive or NewArchive method is called.

Example: The following example shows how to display the type of an archive:

' Code showing initialization of the Archive object omitted
Response.Write "Archive type = " & Archive.ArchiveType & "<BR>"

See Also: Archive.OpenArchive method, Archive.NewArchive method

Password

A string to be used for setting the password of new files.

Access: Write

Notes: This property is used to set the password of files using the Add method or setting the password before using the Extract method.  You cannot change the password of files in the archive using this method.

Example: The following example shows how to set the password:

Archive.Password = "secret"
Archive.Add "C:\MYPATH\*.*"

See Also: Archive.Add method, Archive.Extract method

TempDir

A string to be used for setting the directory to be used for temporary files.

Access: Read/Write

Default: Your windows temporary directory.

Notes: This property is used to set the location of the temporary directory to be used when the Add method is invoked.

Example: The following example shows how to set the temporary directory:

Archive.TempDir = "C:\WORKINGDIR"

See Also: Archive.Add method

 

 

  Methods

Add

Add Path, {Recurse}, {Flatten}

Adds the files specified in Path to the Archive.

Parameter Description
Path String containing the File path to be used to add files to the Archive. It may contain wildcard characters (* and ?).
Recurse Optional boolean on whether to recurse directories/folders. The default is False.
Flatten Optional boolean on whether to strip directory/folder information before adding the files to the archive. The default is False.

Returns: Nothing

Notes:

The Add method allows you to add files to the Archive. It cannot be used until the OpenArchive or NewArchive method is called.

! Adds are not made permanent until the SaveArchive method is called.

If Recurse is set to True and Flatten is not set to True, relative path information for any files located in subdirectories of Path will be stored in the Archive. This path information is always based on the physical path. Even if you specify a virtual path for the Path parameter, it is first translated to a physical path.

! If a file specified by the Path parameter already exists in the same relative path position, it is overwritten.

Example: The following example shows how to add a group of files to an archive:

Set Archive = Server.CreateObject("File Transfer CS .Archive")
Archive.NewArchive "new.zip"
Archive.Add "foo/*.*", True
Archive.SaveArchive

See Also: Archive.OpenArchive method, Archive.NewArchive method, Archive.SaveArchive method

CloseArchive

CloseArchive

The CloseArchive method closes a currently open archive.  Use this method if you wish to delete a currently open Archive.

Example: The following example shows how to delete an open Archive.

Set Archive = Server.CreateObject("File Transfer CS .Archive")
Archive.NewArchive "new.zip"
Archive.Add "foo/*.*", True
Archive.SaveArchive
Archive.CloseArchive
Set File = Server.CreateObject("File Transfer CS .File")
File.Name = "new.zip"
File.Delete

Delete

Delete Path

Deletes the file specified by Path.

Parameter Description
Path String containing the relative path (if any) and file name to be deleted from the Archive. Wildcard characters are not supported.

Returns: Nothing

Notes:

The Delete method allows you to delete a file from the Archive. It cannot be used until the OpenArchive or NewArchive method is called.

! Deletes are not made permanent until the SaveArchive method is called. Once SaveArchive is called, any files deleted can not be restored.

Example: The following example shows how to delete a specific file in an archive:

Set Archive = Server.CreateObject("File Transfer CS .Archive")
Archive.OpenArchive "foo.zip"
Archive.Delete "readme.html"
Archive.SaveArchive

See Also: Archive.OpenArchive method, Archive.NewArchive method, Archive.SaveArchive method

Extract

Extract SourcePath, DestPath

Extracts the files specified in SourcePath from the Archive to DestPath in the server's file system.

Parameter Description
SourcePath String containing the relative path (if any) and file name to be used to extract files from the Archive. The file name may contain wildcard characters (* and ?).
DestPath String containing the path where the files should be extracted to. If the path contains directory/folder information they will be created automatically.

Returns: Nothing

Notes:  The Extract method allows you to extract files from the Archive. It cannot be used until the OpenArchive or NewArchive method is called.

! Any extracted files that already exist in the DestPath folder will be overwritten.

Example: The following example shows how to extract all of the text files located in a specific folder from an archive:

Set Archive = Server.CreateObject("File Transfer CS .Archive")
Archive.OpenArchive "foo.zip"
Archive.Extract "bar\*.txt","C:\temp"

See Also: Archive.OpenArchive method, Archive.NewArchive method

NewArchive

NewArchive Path {,ArchiveType}

Creates a new Archive.

Parameter Description
Path String containing the path for the new Archive.
ArchiveType Optional long value indicating the type of archive. See ArchiveType property for valid values.

Returns: Nothing

Notes: The NewArchive method allows you to create a new Archive. If ArchiveType is not specified, the type of archive created will be based on the file extension specified in Path as follows:

File Extension Archive Type
.ZIP Zip Archive
.SIT Stuffit Archive
.TAR TAR Archive
.GZ GnuZip Archive
.BIN MacBinary Archive

An error occurs if ArchiveType is not specified and the extension does not match any of the above supported extensions.

! The file is not actually created until the SaveArchive method is called.

Example: The following example shows how to create a new archive:

Set Archive = Server.CreateObject("File Transfer CS .Archive")
Archive.NewArchive "new.zip"

See Also: Archive.ArchiveType property, Archive.NewArchive method, Archive.SaveArchive method

OpenArchive

OpenArchive Path

Opens an existing Archive.

Parameter Description
Path String containing the path for the Archive.

Returns: Nothing

Notes: The OpenArchive method allows you to open an existing Archive. The type of Archive is automatically determined.

Example: The following example shows how to open an existing archive:

Set Archive = Server.CreateObject("File Transfer CS .Archive")
Archive.OpenArchive "foo.zip"

See Also: Archive.NewArchive method

SaveArchive

SaveArchive {Path}

Saves an existing Archive.

Parameter Description
Path Optional string containing the path for the Archive.

Returns: Nothing

Notes: The SaveArchive method allows you to save an Archive along with any updates made by the Add and Delete methods.

! If you do not call this method, any updates made by the Add and Delete methods will be lost.

If Path is specified the original archive is unchanged and all saved archive represents the original archive with all modifications.

! If Path is not specified the original archive is overwritten and can not be restored.

Example: The following example shows how to save an archive:

' Code showing initialization and updates to the Archive object omitted 
Archive.SaveArchive

See Also: Archive.Add method, Archive.Delete method