File Access Component |
In addition to the native ASP objects (Request, Response, etc.) and the various installable components (Ad Rotator, Browser Capabilities, etc.), you also have access to a third group of objects. These objects are instantiated directly from the Microsoft Scripting Runtime DLL (scrrun.dll ). This DLL contains functionality that is neither in the native ASP objects nor in the VBScript runtime (vbscript.dll ) itself. From the scripting DLL, you can instantiate objects that provide your application with extensive file-manipulation capabilities. (From this DLL, you also can create a Dictionary object that provides you with a way to perform collection-type functions without true collections.) All file manipulation is performed by the FileSystemObject object. Your application will have only one of these, and it represents your application's "window" onto the system's file structures. With this object, you are able to perform some simple functions such as opening and closing files, but the real strength of this object is that through it you are able to instantiate the other file manipulation objects: Drive, Folder, and File. Through these objects, your application has almost all the power over the file system that you have through a command-line interface.

Accessory Files/Required DLL Files |
Scrrun.DLL The dynamic link library that contains all the scripting objects. This DLL is installed by default when you install IIS 4.0 on your web server.

Instantiating Installable Components |
To create an object variable containing an instance of the FileSystemObject component, use the CreateObject method of the Server object. The syntax for the CreateObject method is as follows:
    Set objMyObject = Server.CreateObject(strProgId)
where: objMyObject represents the name of the FileSystemObject variable. strProgId represents the programmatic identifier (ProgID) for the FileSystemObject component, which is Scripting.FileSystemObject. Example
    <%

    ' The following code uses the CreateObject method of
    ' the Server object to instantiate a FileSystemObject.
    Dim fsFileSystemObject
    Set fsFileSystemObject = _
       Server.CreateObject("Scripting.FileSystemObject")

    %>
For more details on the use of the CreateObject method, see its entry in Chapter 9.

Comments/Troubleshooting |
The file access components of scrrun.dll are straightforward to use. When errors occur, the various properties and methods all return error messages that are in accordance with what you would expect if you were to perform a given file operation through the command line. For example, if you attempt to write or read files on the floppy drive on your computer, but you have no disk in the drive, you will receive a "disk not ready" error.

AtEndOfLine (TextStream Object) |
tsObj.AtEndOfLine
A Boolean value that indicates whether the file pointer is at the end of the current line. This is a read-only property.
Parameters
None
Example
The following code instantiates a FileSystemObject and a TextStream object. It then uses the Read method to read one character at a time until the end of the line is reached. Notice that the use of the AtEndOfStream and AtEndOfLine properties are identical.
    <%

    ' Set up constants.
    Const constForReading       = 1
    Const constTristateFalse    = 0

    ' Dimension local variables.
    Dim fsoObject     ' FileSystemObject
    Dim tsObject      ' TextStream Object
    Dim strReturned   ' String variable to hold file contents

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the OpenTextFile method of fsoObject,
    ' create a text file.
    Set tsObject = _
        fsoObject.OpenTextFile("d:\docs\test.txt", _
        constForReading, constTristateFalse)

    ' Read one character at a time until the end of the
    ' line has been reached.
    Do While Not tsObject.AtEndOfLine
       StrReturned = strReturned & tsObject.Read(1)
    Loop
    . . . [additional code]

    %>
Notes
If you attempt to use the AtEndOfLine property with a text file opened for any purpose other than reading, you will receive an error. The AtEndOfLine property will not inform you that you have reached the end of the file.

AtEndOfStream (TextStream Object) |
tsObj.AtEndOfStream
A Boolean value that indicates whether you have reached the end of the current text file. This is a read-only property.
Parameters
None
Example
The following code instantiates a FileSystemObject and a TextStream object. Then it uses the Read method to read one character at a time until the end of the file is reached. Notice that the use of the AtEndOfStream and AtEndOfLine properties are identical.
    <%

    ' Set up constants.
    Const constForReading      = 1
    Const constTristateFalse    = 0

    ' Dimension local variables.
    Dim fsoObject     ' FileSystemObject
    Dim tsObject      ' TextStream Object
    Dim strReturned   ' String variable to hold file contents.

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the OpenTextFile method of fsoObject, create
    ' a text file.
    Set tsObject = _
        fsoObject.OpenTextFile("d:\docs\test.txt", _
        constForReading, constTristateFalse)

    ' Read one character at a time until the end of the
    ' file has been reached
    Do While Not tsObject.AtEndOfStream
       StrReturned = strReturned & tsObject.Read(1)
    Loop
    . . . [additional code]

    %>
Notes
If you attempt to use the AtEndOfStream property with a text file opened for any purpose other than reading, you will receive an error.

Attributes (File Object, Folder Object) |
    Normal
An integer containing a combination of values representing various file system attributes. This property is read-only or read/write depending on the specific file attribute in question. The following table lists the values that the Attributes property can contain. To determine whether a File or Folder object has a particular value, use the bitwise And operator to compare the Attributes property value and the specific constant in which you're interested. If the result is True, then that specific attribute is True. See the following examples.
Attributes Constant | Value | Description
    Normal
| 0 | No attributes are set.
    ReadOnly
| 1 | Read-only. This attribute is read/write.
    Hidden
| 2 | Hidden. This attribute is read/write.
    System
| 4 | System file. This attribute is valid only for File objects and is read/write.
    Volume
| 8 | The drive's volume label. This attribute is read-only.
    Directory
| 16 | Directory. This attribute is read-only.
    Archive
| 32 | Archived. This attribute is read/write.
    Alias
| 64 | A link or shortcut for another file. This attribute is valid only for File objects and is read-only.
    Compressed
| 128 | Compressed. This attribute is valid only for File objects and is read-only.
Parameters
intNewAttributes An integer containing the sum of a file's or folder's attributes. For example, if you wanted to set the Archived and Hidden attributes to True, intNewAttributes would have a value of Hidden + Archive, or 34 (2 + 32). When assigned to the Attributes property, this integer would set these two attributes to True.
Example
The following code uses the Attributes property first with a File object, and then with a Folder object.
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    Dim filObject   ' File Object
    Dim fdrObject   ' Folder Object

    ' Declare constants.
    Const Hidden = 2
    Const Archive = 32

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize the
    ' File object.
    Set filObject = fsoObject.GetFile("d:\docs\test.txt")

    ' Set the Hidden (value = 2) and Archive (value = 32)
    ' attributes for the Test.TXT file.
    filObject.Attributes = (Hidden + Archive)

    ' Using the GetFolder method of fsoObject, initialize
    ' the Folder object.
    Set fdrObject = fsoObject.GetFolder("d:\docs")

    ' Determine whether the folder is itself hidden.
    If (fdrObject.Attributes And Archive) Then
       ' Folder is hidden.
    Else
       ' Folder is NOT hidden.
    End If
    . . . [additional code]

    %>
Notes
If you attempt to use the read-only attributes that deal only with File objects with a Folder object, the result is always a False value. However, if you attempt to set any of the read-only attributes for File or Folder objects, the result is an error. Note that you must explicitly declare constants for use with the File Access components.

AvailableSpace (Drive Object) |
drvObj. AvailableSpace
The number of bytes of space left on the current drive. It is inaccurate for drives with over 2GB of available space. This is a read-only property.
Parameters
None
Example
    <%
    ' Dimension local variables.
    Dim fsoObject       ' FileSystemObject
    Dim drvObject       ' Drive Object
    Dim lngAvailBytes   ' Number of bytes available

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetDrive method of fsoObject, initialize a
    ' Drive object.
    Set drvObject = fsoObject.GetDrive("\\PublicDocs")
    ' Retrieve the amount of space (in bytes) available
    ' on the drive.
    lngAvailBytes = drvObject.AvailableSpace
    . . . [additional code]

    %>
Notes
The only time the value for the AvailableSpace property and the value for the FreeSpace property will be different is if the drive supports quotas. For all practical purposes, you can use these two properties interchangeably.

DateCreated (File Object, Folder Object) |
Obj.DateCreated
A date value that represents the date the file or folder was created. This is a read-only value controlled by the operating system.
Parameters
None
Example
    <%

    ' Dimension local variables.
    Dim fsoObject    ' FileSystemObject.
    Dim fdrObject    ' Folder object.
    Dim datCreated   ' Date variable.

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFolder method of fsoObject, initialize
    ' a Folder object
    Set fdrObject = fsoObject.GetFolder("c:\Docs")
    ' Retrieve the date the folder was created.
    datCreated = fdrObject.DateCreated
    . . . [additional code]

    %>
Notes
The value of this property indicates the date the file was created, not the date the file was written to the current drive.

Drive (File Object, Folder Object) |
Obj.Drive
Returns a Drive with which the File or Folder object is associated. This property is read-only.
Parameters
None
Example
    <%

    ' Dimension local variables.
    Dim fsoObject     ' FileSystemObject
    Dim filObject     ' File Object
    Dim objDrive      ' Drive name

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize
    ' a File object.
    Set filObject = fsoObject.GetFile("PublicDocs.txt")
    ' Retrieve the drive name with which the File object
    ' is associated.
    Set objDrive = filObject.Drive
    ' Note that this drive is actually the current drive
    ' in this case.
    . . . [additional code]

    %>
Notes
The Drive property can represent either a physical, local, or mapped drive or a network share. Because the Drive object's default property is Path, you can assign the drive name to a string as follows:
    strDrive = filObject.Drive
This is really a shorthand version of:
    strDrive = filObject.Drive.Path
If you wish to manipulate the Drive object, though, you must use the Set statement to assign the reference to an object variable. For example:
    Set objDrive = filObject.Drive

FileSystem (Drive Object) |
drvObj.FileSystem
A string value that represents the file system type used to format the current drive. The recognized file system types are CDFS, NTFS, FAT, and FAT32. This is a read-only property.
Parameters
None
Example
    <%

    ' Dimension local variables.
    Dim fsoObject      ' FileSystemObject
    Dim drvObject      ' Drive Object
    Dim strFileSys     ' File system of drive

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetDrive method of fsoObject, initialize
    ' a Drive object.
    Set drvObject = fsoObject.GetDrive("\\PublicDocs")
    ' Retrieve the file system for the drive. This value
    ' will contain one of the following strings:
    ' NTFS, FAT, or CDFS.
    strFileSys = drvObject.FileSystem
    . . . [additional code]

    %>
Notes
You can rely on the value of the FileSystem property of a Drive object to reflect cluster sizes and security features available for the current drive.

IsReady (Drive Object) |
drvObj.IsReady
A Boolean value representing whether the current drive is available for reading or writing. Use this property, for example, to determine whether a floppy disk or CD has been placed in a drive. This is a read-only property.
Parameters
None
Example
    <%

    ' Dimension local variables.
    Dim fsoObject      ' FileSystemObject
    Dim drvObject      ' Drive Object

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject(
                    "Scripting.FileSystemObject")
    ' Using the GetDrive method of fsoObject, initialize a
    ' Drive object.
    Set drvObject = fsoObject.GetDrive("\\PublicDocs")
    ' Check to see if the drive is ready.
    If drvObject.IsReady Then
       ' Drive is ready for read/write.
    Else
       ' Drive is not ready.
    End If
    . . . [additional code]

    %>
Notes
It is a good idea to use the IsReady property before attempting to do any drive access. It can be used to determine the readiness of removable-media drives (floppy and CD-ROM drives) and fixed-media drives.

IsRootFolder (Folder Object) |
fdr.IsRootFolder
A Boolean value that allows you to determine if the current folder is the root folder. This is a read-only property.
Parameters
None
Example
    <%

    ' Dimension local variables.
    Dim fsoObject      ' FileSystemObject
    Dim fdrObject      ' Folder Object

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFolder method of fsoObject, initialize a
    ' File object.
    Set fdrObject = fsoObject.GetFolder("PublicDocs.txt")
    ' Determine whether the current folder is a root folder
    ' or if it is nested.
    If fdrObject.IsRootFolder Then
       ' Folder is located directly off the drive letter
       ' or share name.
    Else
       ' The folder is nested within at least one other
       ' folder.
    End If
    . . . [additional code]

    %>
Notes
The Microsoft documentation shows how to use this property to determine to how many levels the current folder is nested. For convenience, the following code demonstrates this:
    <%

    ' Dimension local variables.
    Dim fsoObject      ' FileSystemObject
    Dim fdrObject      ' Folder Object
    Dim intNestedLevel ' Level to which the folder is nested

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFolder method of fsoObject, initialize a
    ' File object.
    Set fdrObject = fsoObject.GetFolder("PublicDocs.txt")
    ' Determine whether the current folder is a root folder
    ' or if it is nested.
    If fdrObject.IsRootFolder Then
       ' Folder is located directly off the drive letter or
       ' share name.
    Else
       ' For more on the ParentFolder property of the
       ' Folder object, see the following.
       Do Until fdrObject.IsRootFolder
          Set fdrObject = fdrObject.ParentFolder
          intNestedLevel = intNestedLevel + 1
       Loop
    End If
    . . . [additional code]

    %>

ParentFolder (File Object, Folder Object) |
Obj.ParentFolder
Returns a Folder object representing the folder in which the file or folder is located. This is a read-only property.
Parameters
None
Example
The following code demonstrates the use of the ParentFolder property when used with a File object and then with a Folder object. Note that, because Name is the default property of a Folder object, the code in the ASP page appears to treat the value returned by the ParentFolder property as a string.
    <%

    ' Dimension local variables.
    Dim fsoObject        ' FileSystemObject
    Dim filObject        ' File Object
    Dim fdrObject        ' Folder Object
    Dim strFileParent    ' Parent folder of file object
    Dim strFolderParent  ' Parent folder of folder object

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize the
    ' File object.
    Set filObject = fsoObject.GetFile("d:\docs\test.txt")

    ' Retrieve the name of the folder containing the file Test.TXT.
    ' In this example, the value of strFileParent is "docs".
    strFileParent = filObject.ParentFolder
    ' Using the GetFolder method of fsoObject, initialize
    ' the Folder object.
    Set fdrObject = fsoObject.GetFolder("d:\mystuff\docs")

    ' Retrieve the name of the folder that contains the
    ' folder "docs". In this example, the value of
    ' strFileParent is "mystuff".
    strFolderParent = fdrObject.ParentFolder
    . . . [additional code]

    %>

Close (TextStream Object) |
tsObj.Close
Closes a text file that has been opened as a TextStream object.
Parameters
None
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    Dim tsObject    ' TextStream Object

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the OpenTextFile method of fsoObject, initialize
    ' the File object.
    Set tsObject = fsoObject.OpenTextFile( _
                   "d:\docs\test.txt", ForReading, False)

    ' Read into the string the contents of the text file.
    strContents = tsObject.ReadAll
    ' Close the open text file.
    tsObject.Close
    . . . [additional code]

    %>
Notes
You can have only a limited number of open files in your application (similar to the use of open files in Visual Basic), so it is important to close all open text files after you are finished with them.

Copy (File Object, Folder Object) |
obj.Copy strDestination [, blnOverWrite]
Copies a file from one location to another.
Parameters
strDestination A string value that represents the full path of the location to which you wish to copy the current file. blnOverWrite A Boolean value that indicates whether a file of the same name as the file to be copied will be overwritten. The default is True.
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    Dim filObject   ' File Object

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize
    ' the File object.
    Set filObject = fsoObject.GetFile("d:\docs\test.txt")

    ' Copy the file to a temporary directory.
    filObject.Copy "e:\storage\temp\test_copy.txt", True
    . . . [additional code]

    %>
Notes
The Copy method performs exactly the same function as the CopyFile and CopyFolder methods of the FileSystemObject object. However, it is important to note that the CopyFile and CopyFolder methods will allow you to copy more than one file or folder at a time.

CopyFolder (FileSystemObject Object) |
fsoObj.CopyFolder strSource, strDestination [, blnOverWrite]
Allows you to copy a folder and all of its contents from one location to another.
Parameters
strSource A string value that represents the full path of the location from which you wish to copy a folder or folders. strSource can include wildcard characters. strDestination A string value that represents the full path of the location to which you wish to copy the folder or folders designated by strSource. blnOverWrite A Boolean value that indicates whether a file of the same name as the file to be copied will be overwritten. The default is True.
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Use the FileSystemObject object's CopyFolder method
    ' to copy the Temp directory and all its contents from
    ' the C drive to the D drive, overwriting if necessary.
    fsoObject.CopyFolder "c:\temp", "d:\temp", True
    . . . [additional code]

    %>
Notes
If an error is raised when calling CopyFolder, the method stops immediately and does not reverse any actions already performed. The CopyFolder method is as fast as copying the folder using the command line.

CreateFolder (FileSystemObject Object) |
fsoObj.CreateFolder( strFolderName)
Creates a folder in a specified location.
Parameters
strFolderName A string value that represents the full physical path of the folder you want to create
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Create a new directory.
    fsoObject.CreateFolder("e:\storage\newdir")
    . . . [additional code]

    %>
Notes
If you attempt to create a folder that already exists, an error will be raised.

Delete (File Object, Folder Object) |
Obj.Delete blnForce
Deletes a file or folder.
Parameters
blnForce A Boolean value that indicates whether to delete files or folders, even if they are marked as read-only
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    Dim filObject   ' File Object

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize the
    ' File object.
    Set filObject = fsoObject.GetFile("d:\docs\test.txt")

    ' Delete the TEST.TXT file--even if the file is marked
    ' as read-only.
    filObject.Delete True
    . . . [additional code]

    %>
Notes
The Delete method of the File and Folder objects is functionally the same as the DeleteFile and DeleteFolder methods of the FileSystemObject object. If you use the Delete method of a Folder object, that folder and all of its contents will be deleted. The method will not warn you if you attempt to delete a directory that contains files.

GetBaseName (FileSystemObject Object) |
fsoObj.GetBaseName( strPath)
Extracts the name of a file—minus any file extension—from a full file path.
Parameters
strPath A string representing the full file path of a given file whose base name you want to retrieve
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetBaseName method, retrieve the base
    ' names of several path strings.
    ' This example returns "searchstart" as the base name.
    Response.Write fsoObject.GetBaseName( _
                   "/apps/search/searchstart.asp")
    ' This example returns "search" as the base name.
    Response.Write fsoObject.GetBaseName("/apps/search/")
    ' This example returns "search" as the base name.
    Response.Write fsoObject.GetBaseName("/apps/search")
    ' This example returns "nofile" as the base name--even
    ' though the nofile.txt file does not exist.
    fsoObject.GetBaseName("/apps/search/nofile.txt")
    . . . [additional code]

    %>
Notes
GetBaseName attempts to retrieve the base name for a file from a path string. If the last element in the path string is a folder, the folder name is returned—even if you include a closing slash (/) or backslash (\) character. The path string is not checked for its validity or its existence as a real path on the server. The method just looks at the path as a string. For this reason, the association of this method with the FileSystemObject object is deceiving, since no file manipulation actually occurs.

GetParentFolderName (FileSystemObject Object) |
fsoObj.GetFolderName ( strPath)
Determines the name of the last parent folder in a given path string.
Parameters
strPath A string representing the full file path of a given file or folder whose parent folder name you are attempting to retrieve
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject(
                    "Scripting.FileSystemObject")
    ' Using the GetParentFolderName method, retrieve the
    ' parent folder names of several path strings.
    ' This example returns "search" as the parent folder
    ' name.
    Response.Write fsoObject.GetParentFolderName( _
                   "/apps/search/searchstart.asp")
    ' This example return "apps" as the parent folder name
    Response.Write fsoObject.GetParentFolderName ("/apps/search/")
    ' This example also returns "apps" as the parent folder
    ' name.
    Response.Write fsoObject.GetParentFolderName ("/apps/search")
    ' This example returns "nofile" as the parent folder
    ' name--even though nofile.txt does not exist.
    Response.Write fsoObject.GetParentFolderName( _
                   "/apps/search/nofile.txt")
    . . . [additional code]

    %>
Notes
Like the GetBaseName method of the FileSystemObject object, the GetParentFolderName method acts only on the path string itself. The path string argument is not checked for validity or existence.

GetSpecialFolder (FileSystemObject Object) |
fsoObj.GetSpecialFolder (intSpecialFolderType)
Retrieves the full physical path of a special folder on the web server.
Parameters
intSpecialFolderType An integer that represents the type of special folder whose full physical path you wish to retrieve. The possible values for this parameter are as follows:
Constant | Value | Description
WindowsFolder | 0 | The Windows or WinNT folder into which your operating system was installed
SystemFolder | 1 | The System folder into which libraries and device drivers are installed
TemporaryFolder | 2 | The Temp folder as it is declared in the environment variables
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    ' Declare file constants.
    Const WindowsFolder   = 0
    Const SystemFolder    = 1
    Const TemporaryFolder = 2

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Use GetSpecialFolder to retrieve the physical path
    ' for the Windows, System, and Temp directories.
    ' This example returns something similar to "C:\WINNT".
    fsoObject.GetSpecialFolder(WindowsFolder)
    ' This example returns something similar to
    ' "C:\WINNT\SYSTEM32".
    fsoObject.GetSpecialFolder(SystemFolder)

    ' This example returns something similar to
    ' "C:\WINNT\TEMP"
    fsoObject.GetSpecialFolder(TemporaryFolder)
    . . . [additional code]

    %>
Notes
Note that you must explicitly declare constants for use with the file access components.

MoveFolder (FileSystemObject Object) |
fsoObj.MoveFolder strSourcePath, strDestinationPath
Moves a folder and all its contents from one location to another.
Parameters
strSourcePath A string representing the path to the folder or folders you wish to move. You can include wildcard characters in the strSourcePath argument in the last segment of the path only. strDestinationPath A string representing the path to which you wish to move the folders referenced in the strSourcePath parameter. The strDestinationPath parameter cannot contain any wildcard characters.
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the MoveFolder method, move all the folders
    ' under C:\APPS to the D: drive.
    fsoObject.MoveFolder "C:\APPS\*.*", "D:\"
    . . . [additional code]

    %>
Notes
If you attempt to move a folder to a destination that is already a filename, you will receive an error. If the destination you provide represents the name of a preexisting folder, you will receive an error unless the source argument ends with a wildcard or a backslash (\). In this case, the source folder (or folders) and all its contents will be moved to the destination folder. For example, the following code results in an error:
    <%
    ' Assume FileSystemObject object is instantiated
    'already. Also assume that D:\ apps already exists.
    fsoObject.MoveFolder "C:\apps", "d:\apps"
    %>
whereas the following code would not result in an error:
    <%
    ' Assume FileSystemObject object is instantiated
    ' already. Also assume that D:\ apps already exists.
    fsoObject.MoveFolder "C:\apps\*.*", "d:\apps"
    ' This last line create an apps folder in the D:\apps
    ' folder (making D:\apps\apps)
    %>
Note that if the web server experiences an error when calling MoveFolder, all actions stop without any rollback of previous actions. For example, if you attempt to move a series of three folders with all their contents and an error occurs on the third folder to be moved, the first two folders remain moved even though the third is not. You must include your own code to check for which files and folders were actually moved and which were not. If you attempt to move folders between volumes, the underlying operating system must support this, and user security on the web server must allow for this.

OpenAsTextStream (File Object) |
tsObject =filObj.OpenAsTextStream [ intAccessMode][, intFormat]
Opens a file and creates a TextStream object that you can use to read or modify the text file. The method returns a TextStream object.
Parameters
intAccessMode An integer that indicates the input/output mode in which you wish to open the text file. Possible values for this parameter are as follows:
Constant | Value | Description
ForReading | 1 | The file will be opened as read-only and cannot be modified by the current TextStream object.
ForWriting | 2 | The file will be opened for writing. If the file already exists when you call the OpenAsTextStream method, the original file is overwritten.
ForAppending | 8 | The file is opened for appending only. You can only add characters to the end of this file.
intFormat An integer that indicates the format of the file to be opened as a TextStream object. The possible values for this parameter are thought of as a single tristate value. The file is Unicode, ASCII, or whichever is the system default. Possible values for this parameter are:
Constant | Value | Description
TristateUseDefault | -2 | The file format will be the same as the default for the web server (Unicode or ASCII).
TristateTrue | -1 | The file format will be Unicode.
TristateFalse | 0 | The file format will be ASCII.
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    Dim filObject   ' File Object
    Dim tsObject    ' TextStream object

    ' Declare File Access constants.
    Const ForAppending = 8
    Const TristateTrue = -1

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize the
    ' File object.
    Set filObject = fsoObject.GetFile("d:\docs\test.txt")

    ' Use the OpenAsTextStream method to open the file for
    ' appending and in Unicode format.
    Set tsObject = filObject.OpenAsTextStream(ForAppending, TristateTrue)
    %>
Notes
The OpenAsTextStream method is virtually equivalent to the OpenTextFile method of the FileSystemObject object. The only difference is that the OpenAsTextStream method also can be used to create a new text file if one does not already exist. Note that you must explicitly declare constants for use with the File Access components.

ReadLine (TextStream Object) |
tsObj.ReadLine
The ReadLine method is similar to the Read method of the TextStream object in that it allows you to read from a text file into a string variable or compare the results of such a read to another entity. However, unlike the Read method, which uses an argument to determine how many characters to read, the ReadLine method reads all characters from the current pointer location to the next newline character.
Parameters
None
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    Dim filObject   ' File Object
    Dim tsObject    ' TextStream object
    Dim strBuffer   ' Holding buffer

    ' Declare file access constants.
    Const ForReading = 1
    Const TristateFalse = 0

    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize the
    ' File object.
    Set filObject = fsoObject.GetFile("d:\docs\test.txt")

    ' Use the OpenAsTextStream method to open the file for
    ' reading and in ASCII format.
    Set tsObject = filObject.OpenAsTextStream(ForReading, TristateFalse)
    ' Use the ReadLine method to read the next line of text
    ' from the text file into the strBuffer variable.
    strBuffer = tsObject.ReadLine
    %>
Notes
After calling the ReadLine method, the current location of the pointer within the file is the character immediately after the last newline character or at the end of file marker. Note that you must explicitly declare constants for use with the File Access components.

Write (TextStream Object) |
tsObj.Write(strWriteString)
Writes a specified string to an open text file at the current location of the file pointer.
Parameters
strWriteString A string that represents the text you wish to write to the open file
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    Dim filObject   ' File Object
    Dim tsObject    ' TextStream object
    Dim strEnding
    ' Declare file access constants.
    Const ForAppending = 8
    Const TristateFalse = 0

    ' Initialize string variable. This string will be
    ' written to the end of the file opened next.
    strEnding = "This is the end, my only friend, the end..."
    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize the
    ' File object.
    Set filObject = fsoObject.GetFile("d:\docs\test.txt")

    ' Use the OpenAsTextStream method to open the file for
    ' appending and in Unicode format.
    Set tsObject = filObject.OpenAsTextStream(ForAppending, TristateFalse)
    ' Write a short string to the end of the opened file.
    tsObject.Write strEnding
    . . . [additional code]

    %>
Notes
The Write method does not place any characters at the beginning or end of each written string. For this reason, if you use the Write method to add to a file, make sure that you include any desired characters (like spaces or newline characters) at the beginning or end of the strings you write to the file.

WriteLine (TextStream Object) |
tsObj.WriteLine([strWriteString])
Writes a string's value into an open file at the location of the pointer within the file. This method also writes a newline character to the end of the added string. Otherwise, it is exactly the same as the Write method. strWriteString A string that represents the text you wish to write to the open text file
Example
    <%

    ' Dimension local variables.
    Dim fsoObject   ' FileSystemObject
    Dim filObject   ' File Object
    Dim tsObject    ' TextStream object
    Dim strEnding
    ' Declare file access constants.
    Const ForAppending = 8
    Const TristateFalse = 0

    ' Initialize a string variable that will be written to
    ' the end of the file opened next.
    strEnding = "This is the end, my only friend, the end..."
    ' Instantiate the FileSystemObject variable.
    Set fsoObject = Server.CreateObject( _
                    "Scripting.FileSystemObject")
    ' Using the GetFile method of fsoObject, initialize the
    ' File object.
    Set filObject = fsoObject.GetFile("d:\docs\test.txt")

    ' Use the OpenAsTextStream method to open the file for
    ' appending and in Unicode format.
    Set tsObject = filObject.OpenAsTextStream(ForAppending, TristateFalse)
    ' Write a short string plus a newline character to the
    ' end of the opened file.
    tsObject.WriteLine strEnding
    . . . [additional code]

    %>
Notes
After calling the WriteLine method, the file pointer will point to the character located immediately after the newline character added to the file.