This section provides a tutorial example on how to use the File class that represents a file of a file system. File class is provided in the Scripting Runtime DLL, scrrun.dll.
File: A class representing a file in a file system. It offers the following
properties and methods:
"Attributes": Property to return the attributes of the file.
"DateCreated": Property to return the date and time when the file was created.
"DateLastAccessed": Property to return the date and time when the file was last accessed.
"DateLastModified": Property to return the date and time when the file was last modified.
"Drive": Property to return the driver letter of the file.
"Name": Property to return the name of the file.
"ParentFolder": Property to return the "Folder" object of the parent folder.
"Path": Property to return the path string of the file.
"ShortName": Property to return the name of the file in 8.3 format.
"ShortPath": Property to return the path string of the file in 8.3 format.
"Size": Property to return the size of the file in bytes.
"Copy(destination[,true|false])": Method to copy the file to the specified destination. The optional
argument [true|false] specifies that the copy operation will override the existing file.
"Delete([true|false])": Method to delete the file. The optional [true|false] argument specifies
that the delete operation will delete the read-only file.
"Move(destination)": Method to move the file to the specified destination.
"OpenAsTextStream([io_mode[,tristate]])": Method to open the file and return
a TextStream object representing the I/O stream to that file.
io_mode(=1|2|8: ForReading|ForWriting|ForAppending) specifies how the file should be openned.
tristate(=-2|-1|0: TristateUserDefault|TristateTrue|TristateFalse) specifies if the file should
be open as Unicode or not.
Here is a sample ASP page to show you how to get detailed information about a file.
<script language="vbscript" runat="server">
' folder_test.asp
' Copyright (c) 1999 by Dr. Herong Yang
' This program shows how to browse the directory tree of a drive.
'
response.write("<html><body>")
response.write("<b>Tests on the File class</b>:<br/>")
' Creating a FileSystemObject object
set fs = CreateObject("Scripting.FileSystemObject")
set f = fs.GetFile("c:\winnt\system32\scrrun.dll")
' Display detailed information about this file
response.write("Path = " & f.Path & "<br/>")
response.write("Name = " & f.Name & "<br/>")
response.write("Short Name = " & f.ShortName & "<br/>")
response.write("Short Path = " & f.ShortPath & "<br/>")
response.write("Drive = " & f.Drive & "<br/>")
response.write("Size = " & f.Size & "<br/>")
response.write("Attributes = " & f.Attributes & "<br/>")
response.write("Date Created = " & f.DateCreated & "<br/>")
response.write("</body></html>")
</script>
Output:
Tests on the File class:
Path = C:\WINNT\system32\scrrun.dll
Name = scrrun.dll
Short Name = scrrun.dll
Short Path = C:\winnt\system32\scrrun.dll
Drive = c:
Size = 147512
Attributes = 32
Date created = 6/26/2001 6:06:58 PM