Directory Object

Directory objects represent system folders (or directories) that you can access with your Active Server Pages application. These folders can be located anywhere on your system including paths that are not web shared.

Collections

ACEs, Files

Properties

Attributes, MaskOwner, Path (default property), SortOrder

Methods

Create, CreateTemp, Delete, Exists, Refresh, Rename

 

  Collections

ACEs

Collection of ACE objects for the directory (NTFS only).

Access: Read/Write
Default: None

Notes: The ACEs collection contains all of the Access Control Entries (ACE) listed in a directory's Access Control List (ACL).  The index into this collection is the ACE trustname - the user or group the ACE is associated with.  For more information see the ACEs collection.

Example 1: The following example shows how to display each user or group with having an ACE setting for the C drive.

Set Dir = Server.CreateObject("ActiveFile.Directory")
Dir.Path = "C:\"
For Each ACE In Dir.ACEs
	Response.Write "Name = " & ACE.TrusteeName & "<BR>"
Next

Example 2: The following example shows how to give a user read permission for a directory.

Set Dir = Server.CreateObject("ActiveFile.Directory")
Dir.Path = "C:\My Documents"
Dir.ACEs.Add "Sam", AF_PERMIT_READ, AF_INHERIT_CONTAINER

See Also: ACE object, ACEs collection

Files

Collection of File objects that are in the folder or directory and match the Mask property

Access: Read
Default: None

Notes: If the Directory object is referencing a valid path, the Files collection will be set to contain a collection of File objects that represent the contents of the directory that match the Mask property. The File objects will appear in the collection in the order specified by the SortOrder property. Even though this property can not be set, the Files contained within the collection can be manipulated using File object methods.

Example: The following example shows how to display the contents of a directory in reverse order

Set Dir = Server.CreateObject("ActiveFile.Directory")
Dir.Path = "C:\"
For I = Dir.Files.Count To 1 Step -1
	Response.Write "File Name = " & Dir.Files(I).Name & "<BR>"
Next

See Also: File object, Directory.Mask property, Directory.SortOrder property

 

 

  Properties

Attributes

A long integer containing a bit mask that represents the file system attributes of the directory.

Access: Read/Write
Default: None

Notes: This property contains various file system attributes for the directory represented as a bit mask. Boolean operations can be used to test and set specific attributes using the constants defined in the table below.

Constant Value Description
AF_ATTRIBUTE_READONLY 1 The directory is read only.
AF_ATTRIBUTE_HIDDEN 2 The directory is a hidden directory.
AF_ATTRIBUTE_SYSTEM 4 The directory is a system directory.
AF_ATTRIBUTE_DIRECTORY 16 This is a directory (always set and read-only)
AF_ATTRIBUTE_ARCHIVE 32 The directory has the archive attribute set.
AF_ATTRIBUTE_COMPRESSED 2048 The directory is compressed (NTFS only and read-only).

The bit for attribute AF_ATTRIBUTE_DIRECTORY is always set and can not be changed. Furthermore, the bit for attribute AF_ATTRIBUTE_COMPRESSED can not be modified.

Example 1: The following example shows how to test to see if the directory is compressed:

' Code showing initialization of the Directory object omitted
If Dir.Attributes And AF_ATTRIBUTE_COMPRESSED Then
    Response.Write "Directory is compressed.<BR>" 
Else
    Response.Write "Directory is not compressed.<BR>"
End If

Example 2: The following example shows how to set the archive attribute for a directory:

' Code showing initialization of the Directory object omitted
Dir.Attributes = Dir.Attributes Or AF_ATTRIBUTE_ARCHIVE

See Also: File object

Mask

String value of the mask for building the directory object.

Access: Read/Write
Default: "*.*"

Notes: The Mask property is useful for limiting the files that show up in the Files collection to those that are of interest.

Example: The following example shows how to set the Mask property to limit the Files collection to only text files:

' Code showing initialization of the Directory object omitted
Dir.Mask = "*.txt"

See Also: Files collection

Owner

String value representing the owner of the directory (NTFS only). This may be a group or a user.

Access: Read/Write
Default: None
Notes:  This property can be useful for displaying the owner of the directory.  While it can also be used to take ownership of directory, you must be logged in under the same account that you are trying to set this property to and that account must have permission to take ownership of the directory. For more information see Security Considerations.

Example 1: The following example shows how to display the owner of a directory:

' Code showing initialization of the Directory object omitted
Response.Write "Owner = " & Dir.Owner & "<BR>"

Example 2: The following example shows how to take ownership of a directory:

' Code showing initialization of the Directory object omitted
Dir.Owner = "sam"

See Also: Security Considerations

Path

String value of the path to the folder or directory.

Access: Read/Write
Default: None

Notes: Path is the default property of the Directory object representing the path of the directory being referenced. Because this is the default property the following are equivalent:

Path = Directory.Path
Path = Directory

This property is automatically set by the Create and CreateTemp methods to the path of the directory that was just created.

While you can set the Path property to point to an existing directory, modifying the Path property will not cause the directory to be renamed. If you want to rename a directory, use the Rename method.

Example: The following example shows how to display the path of the directory:

' Code showing initialization of the Post object omitted
Response.Write "Path = " & Dir & "<BR>"

See Also: Directory.Create method, Directory.CreateTemp method, Directory.Rename method

SortOrder

Variant value specifying the File property to use for sorting the Files collection as shown by the following table.

Access: Read/Write
Default: 0 (sort by FileName)
Notes: The Sort property is useful for sorting the contents of a directory that you wish to display by setting the property to one of the following constants:

Constant Value  Sorts by File Property 
AF_SORT_NAME 0 FileName
AF_SORT_SIZE 1 Size
AF_SORT_MODIFIED 2 LastModified
AF_SORT_EXTENSION 3 FileExtension
AF_SORT_FILETYPE 4 FileType
AF_SORT_MIMETYPE 5 MimeType

Files are always sorted in ascending order. If you need the files sorted in a descending order, simply access the collection in reverse order.

Example: The following example shows how to sort the directory by file size:

' Code showing initialization of the Directory object omitted
Dir.SortOrder = AF_SORT_SIZE

See Also: File object, Files collection

 

 

  Methods

Create

Create Path

Creates a new directory or folder.

Parameter Description
Path String containing the path or folder name

Returns: Nothing

Notes: The Create method can be used to create a new directory in the file system anywhere on the server depending on the type of path.

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

Set Dir = Server.CreateObject("ActiveFile.Directory")
Dir.Create "C:\mydir"

See Also: Directory.CreateTemp method

CreateTemp

CreateTemp Path

Creates a new temporary folder or directory.

Parameter Description
Path String containing the path that will contain the temporary folder or directory.

Returns: Nothing

Notes: The CreateTemp method can be used to create a temporary directory in the file system anywhere on the server depending on the type of path. The temporary directory created will be a subdirectory of the directory referenced by the Path parameter.

Example: The following example shows how to create a temporary directory:

Set Dir = Server.CreateObject("ActiveFile.Directory")
Dir.CreateTemp "C:\temp"

See Also: Directory.Create method

Delete

Delete {Recurse}

Deletes a folder or directory.

Parameter Description
Recurse Optional Boolean indicating whether to delete any files or directories contained within the directory object. The default is False.

Returns: Nothing

Notes: If the Directory object is not empty and Recurse is False or omitted an error will be returned.

!
Use caution when calling this method. Setting Recurse to True will delete all of the contents of the directory and subdirectories. There is no "undo" method.
 

Example: The following example shows how to delete a directory:

' Code showing initialization of the Directory object omitted
Dir.Delete

See Also: File.Delete method

Exists

Exists

Returns true if the directory exists.

Returns: A boolean indicating whether the directory exists or not.

Notes:  The Exists method is useful for checking for the existence of a directory.

Example: The following example shows how to test to see if a directory exists:

' Code showing initialization of the Directory object omitted
If Dir.Exists Then
    Response.Write "Directory exists.<BR>"
Else
    Response.Write "Directory does not exist.<BR>"
End If

See Also: File.Exists method

Refresh

Refresh

Refreshes the contents of a folder or directory object.

Returns: Nothing

Notes:  Refresh should be used if the contents of the directory may have been changed by another component or external process. By calling this method, the directory properties such as the Files collection will be updated to reflect the current state of the file system.

Example: The following example shows how to refresh the directory object:

' Code showing initialization of the Directory object omitted
Dir.Refresh

See Also: Files collection

Rename

Rename Path

Renames the directory to Path.

Parameter Description
Path String containing the target path for the Rename operation.

Returns: Nothing

Notes: The Rename method allows you to rename or move the directory currently being referenced by the Directory object. Afterwards, the Directory object references the directory in the new location.

Example: The following example shows how to rename directory "old" to "new":

Set Dir = Server.CreateObject("ActiveFile.Directory")
Dir.Path = "C:\old"
Dir.Rename "C:\new"

See Also: Directory.Path property

 

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