ASP Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.11

Microsoft Scripting Runtime DLL

Part:   1  2  3  4 

ASP Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

hyBook - Guestbook Application

Using MS Access Databases

ActiveX Data Object (ADO)

Controlling Response Header Lines

Microsoft Scripting Runtime DLL

Using Cookies

ASP Sessions

ASP Objects

Microsoft Script Debugger

Internet Information Services (IIS)

... Table of Contents

(Continued from previous part...)

"File" Class

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]])": Methode 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) speficies 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

"TextStream" Class

TextStream: A class representing an I/O stream connected to a file. It offers the following properties and methods:

  • "AtEndOfLine": Property to return true if the current reading position is before the end of a line.
  • "AtEndOfStream": Property to return true if the current reading position is before the end of the file.
  • "Column": Property to return the column number of the current position.
  • "Line": Property to return the line number of the current position.
  • "Close()":
  • "Read(n)": Method to return a string of characters up to the specified number.
  • "ReadAll()": Method to return a string of the rest characters in the stream.
  • "ReadLine()": Method to return a string of the rest characters in the linie.
  • "Skip(n)":
  • "SkipLine()":
  • "Write(string)":
  • "WriteLine([stsring])":
  • "WriteBlankLines(n))":

Here is a sample ASP page to show you how to create and open a text file.

<script language="vbscript" runat="server">
'  text_stream_test.asp
'  Copyright (c) 1999 by Dr. Herong Yang
'  This program shows how to create and open files as text stream 
'  objects.
'
   response.write("<html><body>")
   response.write("<b>Tests on the TextStream class</b>:<br/>")
   ' Getting the FileSystemObject
   set fs = CreateObject("Scripting.FileSystemObject")
   ' Creating a new file for writing
   set out = fs.CreateTextFile("c:\temp\test.txt",true,false)
   out.WriteLine("FirstName=Bill")
   out.WriteLine("LastName=Smith")
   out.WriteLine("Email=bill@com.com")
   out.Close()
   ' Open an existing file for reading
   set inn = fs.OpenTextFile("c:\temp\test.txt",1)
   while inn.AtEndOfStream = false
      line = inn.ReadLine()
      response.write(line & "<br/>")
   wend
   inn.Close()
   response.write("</body></html>")
</script>

Output:

Tests on TextStream class:
FirstName=Bill
LastName=Smith
Email=bill@com.com

Note that:

  • If you look at the directory c:\temp, you will a new file "test.txt".
  • You can not create new files in c:\inetpub\wwwroot. If you try, you will get "permission denied" error message.
  • "in" seems to be a reserved word. So I used "inn" as a variable name.
  • "wend" ends the "while" statement. I really don't know why the designers can not use "end while".

Part:   1  2  3  4 

Dr. Herong Yang, updated in 2002
ASP Tutorials - Herong's Tutorial Notes - Microsoft Scripting Runtime DLL