The Folder object allows you to interrogate the system properties of the folder and provides
methods
that allow you to copy, move, and delete the folder. You can also create a new text file within the folder.
The Folder object is unusual because with it, you can gain access to a Folders collection object. The more usual method is to extract a member of a collection to gain access to the individual object. However, because the Drive object exposes only a Folder object for the root folder, you have to extract a Folders collection object from a Folder object (the collection represents the subfolders of the root). From this collection, you can navigate downward through the filesystem to extract other Folder objects and other Folders collections. A Boolean property, IsRootFolder, informs you of whether the Folder object you are dealing with currently is the root of the drive.
The Folder object is one of the objects in the Filesystem object model; for an overview of the model, see the "File System Object Model" entry.
-
Attributes
-
Data Type: Long
A set of flags representing the folder's attributes. The flags that apply to folders are:
|
Archive
|
32
|
|
Directory
|
16
|
|
Hidden
|
2
|
|
ReadOnly
|
1
|
|
System
|
4
|
As the table shows, the Scripting Runtime type library defines constants of the
FileAttribute
enumeration that can be used in place of their numeric equivalents. You can use them in your scripts in either of two ways. You can define the constants yourself by adding the following code to your script:
Const Normal = 0
Const ReadOnly = 1
Const Hidden = 2
Const System = 4
Const Directory = 16
Const Archive = 32
Or you can take advantage of the host's facilities to make the constants accessible. In Active Server Pages, you can include the
METADATA
tag in the
global.asa
file and provide the type library identifier for the Scripting Runtime as
follows
:
<!-- METADATA TYPE="TypeLib"
UUID="420B2830-E718-11CF-893D-00A0C9054228"
-->
In Windows Script Host, you can include the following line in a
.wsf
file in order to access the constants defined in the Scripting Runtime:
<reference GUID="" />
You can determine which flag is set by using a logical AND along with the value returned by the property and the value of the flag you'd like to test. For example:
If oFolder.Attributes And ReadOnly Then
' Folder is read-only
To clear a flag,
And
the value of the Attributes property with a Long in which the flag you want to clear is turned off. For example, the following code clears a Folder object's read-only flag:
oFile.Attributes = oFile.Attributes And (Not
ReadOnly)
-
Date Created
-
Data Type: Date
The date and time the folder was created.
-
DateLastAccessed
-
Data Type: Date
The date and, if it's available from the operating system, the time that the folder was last accessed.
-
DateLastModified
-
Data Type: Date
The date and time the folder was last modified.
-
Drive
-
Data Type: Drive object
Returns a Drive object representing the drive on which this folder resides; the property is read-only.
-
Files
-
Data Type: Files collection object
Returns a read-only Files collection object representing all files in the current folder.
-
IsRootFolder
-
Data Type: Boolean
Returns
True
if the folder is the root folder of its drive.
-
Name
-
Data Type: String
Returns the name of the folder.
-
ParentFolder
-
Data Type: Folder object
Returns a folder object representing the folder that's the parent of the current folder. It returns
Nothing
if the current object is the root folder of its drive (i.e., if its IsRootFolder property is
True
).
-
Path
-
Data Type: String
Returns the complete path of the current folder, including its drive. It is the default property of the Folder object.
-
ShortName
-
Data Type: String
Returns a DOS 8.3 folder name without the folder's path. The property is read-only.
-
ShortPath
-
Data Type: String
Returns the complete path to a folder in DOS 8.3 format. The property is read-only.
-
Size
-
Data Type: Long
Returns the total size of all files, subfolders, and their contents in the folder structure, starting with the current folder. The property is read-only.
In previous versions of the Scripting Runtime, this property failed to accurately report the size of a folder whose files and subfolders occupied more than 2 GB of disk space.
Attempting to retrieve the value of a Folder object's Size property when that folder is a drive's root folder (that is, its IsRootFolder property returns True) generates a runtime error.
-
SubFolders
-
Data Type: Folders collection object
Returns a Folders collection object representing all subfolders within the current folder.
-
Type
-
Data Type: String
Returns the description of a filesystem object, as recorded in the system registry. For Folder objects, the property always returns "File Folder."