...

View Full Version : how to delete line in text file



bmwmpower
10-22-2003, 02:22 PM
in the first i like this web site so much


about my problem i need help in how i can delete line in text file

i have code in chatting module this code save the chatting in text file so i need help in how i can deletle the first line when the lines comes 500 lines
i need idea how i can make this array
this array made to delete the first line when the lines come to the max (200 line)

glenngv
10-23-2003, 06:27 AM
try:

dim filesys, readfile, contents, arrContents
const maxlen = 500
set filesys = CreateObject("Scripting.FileSystemObject")
set readfile = filesys.OpenTextFile("c:\somefile.txt", 1, false)
contents = readfile.ReadAll
readfile.close

arrContents = split(contents,VbCrLf)
if ubound(arrContents) = maxlen - 1 then
'already reached the max line number
else
'not yet reached the max line number
end if

bmwmpower
10-23-2003, 09:26 AM
thanks for your help
but how i can delete the first line in the text file

glenngv
10-23-2003, 09:36 AM
set the first item in the array empty

arrContents = split(contents, VbCrLf)
if ubound(arrContents) = maxlen - 1 then

'already reached the max line number
arrContents(0)=""
contents = Join(arrContents, VbCrLf) 'convert back to string
'do other stuff

else

'not yet reached the max line number

end if

bmwmpower
10-23-2003, 10:15 AM
does't work i can tell u my code may be i have problem in this code

Set fileObject = Server.CreateObject("Scripting.FileSystemObject")
textFile = c:\somefile.txt

If Not fileObject.FileExists(textfile) Then
Set inStream = fileObject.OpenTextFile(textFile,8,True,FALSE)
nStream.WriteLine " "
End If

Set inStream = fileObject.OpenTextFile(textFile,1,TRUE,FALSE)
contents = inStream.ReadAll
Set inStream = Nothing

const maxlen = 200
arrContents = split(contents, VbCrLf)
if ubound(arrContents) = maxlen - 1 then

'already reached the max line number
arrContents(0)=""
contents = Join(arrContents, VbCrLf) 'convert back to string
'do other stuff

else

'not yet reached the max line number

end if

If IsNull(Session("Enter")) Or Session("Enter") = True Then
Session("Enter") = False
End If

If Request.Form("Add") = "TRUE" Then
file = file & "<FONT SIZE=2 Color=#000000 FACE='Verdana,Arial'><b>" & name & "</b></FONT><FONT FACE='Vedana,Arial' Color=#0000FF SIZE=1 >("& date &"-"& timeaa &" GMT):</FONT>" & Request("Msg") & "<br>"


Set outStream = fileObject.CreateTextFile(textFile,True)
outStream.WriteLine(contents)
Set outStream = Nothing

End If

Response.Write "<font color=#000000>" & contents & ""

i have comment this code not delete the first line i need delete the first line form the text file

glenngv
10-23-2003, 10:44 AM
you're not closing the inStream and outStream objects.

If Not fileObject.FileExists(textfile) Then
Set inStream = fileObject.OpenTextFile(textFile,8,True,FALSE)
inStream.WriteLine " "
inStream.Close
End If

Set outStream = fileObject.CreateTextFile(textFile,True)
outStream.WriteLine(contents)
outStream.Close
Set outStream = Nothing



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum