VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "FileIO"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' Class FileIO
Option Explicit
Private objApplication As Application ' Reference to Application object
Private objResponse As Response ' Reference to Response object
' OnStartPage():
'
' This procedure is called when an instance of this class is created in an
' Active Server Page. It gets references to the Application and Response
' objects that are being used in the ASP page that created the instance of
' this class.
'
Public Sub OnStartPage(objScriptingContext As ScriptingContext)
Set objApplication = objScriptingContext.Application()
Set objResponse = objScriptingContext.Response()
End Sub
' OnEndPage():
'
' This procedure is called when an instance of this class is destroyed in
' an Active Server Page. It is used to clean up object references.
'
Public Sub OnEndPage()
Set objApplication = Nothing
Set objResponse = Nothing
End Sub
' help():
'
' Writes help information to the response stream.
'
Public Sub help()
objResponse.Write "
Class FileIO
" & vbCrLf
objResponse.Write "Usage:" & vbCrLf
objResponse.Write "set o = Server.CreateObject(""ASCExample.FileIO"")" & vbCrLf
objResponse.Write "Methods:" & vbCrLf
objResponse.Write "
" & vbCrLf
objResponse.Write "- help() - shows help" & vbCrLf
objResponse.Write "
- fileSize(strName) - returns size of named file" & vbCrLf
objResponse.Write "
- fileExists(strName) - returns True if named file exists" & vbCrLf
objResponse.Write "
- deleteFile(strName) - deletes named file" & vbCrLf
objResponse.Write "
- appendLine(strName, strLine) - appends line to file" & vbCrLf
objResponse.Write "
" & vbCrLf
End Sub
' fileSize():
'
' Returns the size of the file with the given name.
'
Public Function fileSize(strFileName) As Long
fileSize = FileLen(strFileName)
End Function
' fileExists():
'
' Returns True if the specified file exists. Note that the given file
' specification can contain wildcard characters.
'
Public Function fileExists(strFileSpec) As Boolean
fileExists = (Dir(strFileSpec) <> "")
End Function
' deleteFile():
'
' Deletes files that match the given file specification, which can include
' wildcard characters.
'
Public Sub deleteFile(strFileSpec)
Call Kill(strFileSpec)
End Sub
' appendLine():
'
' Appends a line to a text file (which is handy when working with log
' files.)
'
Public Sub appendLine(strFileName, strLine)
Dim objFileSystem As FileSystemObject
Dim objStream As TextStream
Set objFileSystem = New FileSystemObject
Set objStream = objFileSystem.OpenTextFile(strFileName, 8, True, False)
objStream.WriteLine strLine
objStream.Close
End Sub
' End Class FileIO