%
'-------------------------------------------------------------------------------
'Author: Tommy Johannessen
'Date : 13.feb 2003
'E-mail: tj@morrowland.com
'All rights reserved Morrowland © 2002
'-------------------------------------------------------------------------------
Class TextFileInterface
'----------------------------------------------------
' This method get the content of a file (without line breaks)
'----------------------------------------------------
Public Property Get GetAllTextContent(filename)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'open the file
Set f=fs.OpenTextFile(Server.MapPath(filename), 1)
GetAllTextContent = f.ReadAll
'close the file
f.Close
'empty the objects
Set f=Nothing
Set fs=Nothing
End Property
'----------------------------------------------------
' This method get the content of a file (with line breaks)
'----------------------------------------------------
Public Property Get GetAllTextContentWithBreak(filename)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'open the file
Set f=fs.OpenTextFile(Server.MapPath(filename), 1)
do while f.AtEndOfStream = false
GetAllTextContentWithBreak = GetAllTextContentWithBreak & f.ReadLine & "
"
loop
f.Close
'empty the objects
Set f=Nothing
Set fs=Nothing
End Property
'----------------------------------------------------
' This method replaces words
'----------------------------------------------------
Public Function ReplaceWords(filename, newword, oldword)
Dim content
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'open the file
Set f=fs.OpenTextFile(Server.MapPath(filename), 1)
content = f.ReadAll
content = replace(content, oldword, newword)
f.Close
Set f=fs.CreateTextFile(filename,true)
f.write(Server.MapPath(content))
f.Close
'empty the objects
Set f=nothing
Set fs=nothing
End Function
'----------------------------------------------------
' This method removes a line
'----------------------------------------------------
Public Function InsertLineBefore(filename, linenr, addcontent)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Dim count, content
count = 0
'open the file
Set f=fs.OpenTextFile(Server.MapPath(filename), 1)
do while f.AtEndOfStream = false
count = count + 1
If linenr = count Then content = content & addcontent & "
"
content = content & f.ReadLine & "
"
loop
f.Close
Set f=fs.CreateTextFile(filename,true)
f.write(Server.MapPath(content))
f.Close
'empty the objects
Set f=nothing
Set fs=nothing
End Function
'----------------------------------------------------
' This method removes a line
'----------------------------------------------------
Public Function InsertLineAfter(filename, linenr, addcontent)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Dim count, content
count = 0
'open the file
Set f=fs.OpenTextFile(Server.MapPath(filename), 1)
do while f.AtEndOfStream = false
count = count + 1
content = content & f.ReadLine & "
"
If linenr = count Then content = content & addcontent & "
"
loop
f.Close
Set f=fs.CreateTextFile(filename,true)
f.write(Server.MapPath(content))
f.Close
'empty the objects
Set f=nothing
Set fs=nothing
End Function
'----------------------------------------------------
' This method deletes a word
'----------------------------------------------------
Public Function DeleteWord(filename, word)
Dim content
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'open the file
Set f=fs.OpenTextFile(Server.MapPath(filename), 1)
'get all the data
content = f.ReadAll
content = replace(content, word, "")
'close the file
f.Close
Set f=fs.CreateTextFile(filename,true)
f.write(Server.MapPath(content))
f.Close
'empty the objects
Set f=nothing
Set fs=nothing
End Function
'----------------------------------------------------
' This method removes a line
'----------------------------------------------------
Public Function DeleteLine(filename, linenr)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Dim count, content
count = 0
'open the file
Set f=fs.OpenTextFile(Server.MapPath(filename), 1)
do while f.AtEndOfStream = false
count = count + 1
If linenr <> count Then
content = content & f.ReadLine & "
"
Else
f.ReadLine
End If
loop
f.Close
Set f=fs.CreateTextFile(filename,true)
f.write(Server.MapPath(content))
f.Close
'empty the objects
Set f=nothing
Set fs=nothing
End Function
'----------------------------------------------------
' This makes/write to a file
'----------------------------------------------------
Public Function MakeFile(filename, content)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.CreateTextFile(filename,true)
f.write(Server.MapPath(content))
f.close
Set f=nothing
Set fs=nothing
End Function
'----------------------------------------------------
' This delete a file
'----------------------------------------------------
Public Function DeleteFile(filename)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile(Server.MapPath(filename))
f.Delete
Set f=nothing
Set fs=nothing
End Function
End Class
%>