Text file Operation class Txtfiledump version 2.4

Source: Internet
Author: User
Tags exit readline

<%
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
''''
"' Fso.asp
''''
"" Sub:checkfolder (Aimfolder)
"' Class:txtfiledump
''''
"' version:2.4 last-modified:2005-04-11 12:36
"" Copyright:xinsoft (blogchina.com)
''''
''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''
%><%
'/check to see if the destination folder exists. If you do not save the word, create it.
Sub Checkfolder (Aimfolder)
Dim Hasfolder
Dim Realpath
"Realpath=server.mappath" (Aimfolder)
Realpath=aimfolder
Hasfolder=true

Dim Folda,foldn,i,curfolder,hascur

Dim FSO
Set fso = CreateObject ("Scripting.FileSystemObject")
Hasfolder=fso. FolderExists (Realpath)

If hasfolder<>true Then
' FSO. CreateFolder (Realpath)
' Response.Write fso. GetSpecialFolder
"' Response.Write Realpath
Folda=split (Realpath, "\")
Foldn=ubound (Folda) +1

Curfolder=folda (0) & "\"
For I=1 to FoldN-1
Curfolder=curfolder & Folda (i) & "\"

Hascur=fso. FolderExists (CurFolder)
If hascur<>true Then FSO. CreateFolder (CurFolder)

"Response.Write" <p>hascur= "& Hascur &", "& CurFolder &" </p> "
Next

End If

Set fso=nothing
End Sub
%>
<%

Class Txtfiledump


Public FilePath
Public FileName


Private Rowa
Private Rown

Private FSO

'//Read the file into Rowa and set Rown=count (line)
Public Sub Read ()
Dim F,i

Set f=fso.opentextfile (FilePath & FileName, 1)
Rown=0
Do as not F.atendofstream
Rown=rown+1
F.skipline
Loop
F.close
ReDim Rowa (Rown)
Set f=fso.opentextfile (FilePath & FileName, 1)
I=0
Do as not F.atendofstream
Rowa (i) =f.readline
I=i+1
Loop
F.close

Set f=nothing
End Sub
'//View content in Rowa
Public Sub Showdumpcont ()
Dim I
For I=0 to RowN-1
Response.Write Rowa (i) & VBCrLf
Next
End Sub

'//return one line in file
Property Get Line (Ilinenumber)
Dim ival
Ival=ilinenumber
If ival<1 Then ival=1
If Ival>rown Then Ival=rown
Line=rowa (IVAL-1)
End Property
Property Get LineCount ()
Linecount=rown
End Property

'//Get the line number which include string (s) in file
"//Search Order:from begin to end of the file
Property Get Find (s)
Dim I
Dim Flag
Flag=0
For I=0 to RowN-1
If InStr (Rowa (i), s) >0 Then
Flag=i+1
Exit for
End If
Next
Find=flag
End Property

'//Get the line number which include a string (s) in file between lines (Ibegin ... iend)
"//Search Order:from begin to end of the file
Property Get Findarea (S, ibegin,iend)
Dim I
Dim Flag
Dim Ib,ie

Ib=ibegin
If ibegin<1 Then ib=1
If Ibegin>rown Then Ib=rown
Ie=iend
If Ie<ib Then Ie=ib
If Ie>rown Then Ie=rown

Flag=0
For I=0 to RowN-1
If i>=ib-1 and I<=ie-1 Then
If InStr (Rowa (i), s) >0 Then
Flag=i+1
Exit for
End If
End If
Next
Findarea=flag
End Property

'//Get the line number which include string (s) in file
"//Search Order:from end to begin of the file
Property Get Findrev (s)
Dim I
Dim Flag

Flag=0
For i=rown-1 to 0 Step-1
If InStr (Rowa (i), s) >0 Then
Flag=i+1
Exit for
End If
Next
Findrev=flag
End Property

'//Get the line number which include a string (s) in file between lines (Ibegin ... iend)
"//Search Order:from end to begin of the file
Property Get Findarearev (S, ibegin,iend)
Dim I
Dim Flag
Dim Ib,ie

Ib=ibegin
If ibegin<1 Then ib=1
If Ibegin>rown Then Ib=rown
Ie=iend
If Ie<ib Then Ie=ib
If Ie>rown Then Ie=rown

Flag=0
For i=rown-1 to 0 Step-1
If i>=ib-1 and I<=ie-1 Then
If InStr (Rowa (i), s) >0 Then
Flag=i+1
Exit for
End If
End If
Next
Findarearev=flag
End Property

Public Function sfind (str)
Dim I
Dim Flag
Dim s
S=lcase (str)
Flag=0
For I=0 to RowN-1
If InStr (Lcase (Rowa (i)), s) >0 Then
Flag=i+1
Exit for
End If
Next
Sfind=flag
End Function

Public Function Sfindrev (str)
Dim I
Dim Flag
Dim s
S=lcase (str)
Flag=0
For i=rown-1 to 0 Step-1
If InStr (Lcase (Rowa (i)), s) >0 Then
Flag=i+1
Exit for
End If
Next
Sfindrev=flag
End Function

'//Get the line number which include string (s) in file before the given line number
"//Search Order:from begin to end of the file
Property Get Findu (S, IPos)
Dim I
Dim Flag
Dim IP

Ip=ipos

Flag=0
For i=rown-1 to 0 Step-1
If i<ipos-1 Then
If InStr (Rowa (i), s) >0 Then
Flag=i+1
Exit for
End If
End If
Next
Findu=flag
End Property

"//Get" line number which include string (s) in file after the given line number
"//Search Order:from begin to end of the file
Property Get Findd (S, IPos)
Dim I
Dim Flag
Dim IP

Ip=ipos

Flag=0
For I=0 to RowN-1
If i>ipos-1 Then
If InStr (Rowa (i), s) >0 Then
Flag=i+1
Exit for
End If
End If
Next
Findd=flag
End Property

Public Sub Savelines (ibegin,iend)
Dim F,i
Dim Ib,ie

Ib=ibegin
If ibegin<1 Then ib=1
If Ibegin>rown Then Ib=rown

Ie=iend
If Iend<=ibegin Then Ie=ib
If Iend>rown Then Ie=rown

If FSO. FileExists (FilePath & FileName) =true Then
Fso. DeleteFile (FilePath & FileName)
End If

Set f=fso.opentextfile (FilePath & FileName, 2, True)
For I=ib-1 to IE-1
F.writeline (Rowa (i))
Next
F.close
Set f=nothing

Read

End Sub

Public Sub Save ()
Savelines 1,rown

Read

End Sub

Public Sub Cutlines (Ibegin, Iend)
Dim F,i
Dim Ib,ie

Ib=ibegin
If ibegin<1 Then ib=1
If Ibegin>rown Then Ib=rown

Ie=iend
If Iend<=ibegin Then Ie=ib
If Iend>rown Then Ie=rown

If FSO. FileExists (FilePath & FileName) =true Then
Fso. DeleteFile (FilePath & FileName)
End If

Set f=fso.opentextfile (FilePath & FileName, 2, True)
For I=0 to RowN-1
If i<ibegin-1 Or i>iend-1 Then
F.writeline (Rowa (i))
End If
Next
F.close
Set f=nothing

Read

End Sub

'//Content Replace and save
Public Function replacecontinlines (SRCSTR,DESSTR, Ibegin,iend)

Read

Dim Replacetimes
Replacetimes=0
Dim F,i
Dim Ib,ie

Ib=ibegin
If ibegin<1 Then ib=1
If Ibegin>rown Then Ib=rown

Ie=iend
If Iend<=ibegin Then Ie=ib
If Iend>rown Then Ie=rown

If FSO. FileExists (FilePath & FileName) =true Then
Fso. DeleteFile (FilePath & FileName)
End If

Set f=fso.opentextfile (FilePath & FileName, 2, True)
For I=0 to RowN-1
If Ibegin-1<=i and I<=iend-1 Then
If InStr (Rowa (i), srcstr) >0 Then
Rowa (i) =replace (Rowa (i), srcstr,desstr)
Replacetimes=replacetimes+1
End If
End If
F.writeline (Rowa (i))
Next
F.close
Set f=nothing

Read

Replacecontinlines=replacetimes
End Function

Public Function Replacecont (SRCSTR,DESSTR)
Replacecont=replacecontinlines (Srcstr,desstr,1,rown)
End Function

'//File Coalition
Public Sub Coalitbefore (FP,FN)
Dim RECA,RECN
Dim F,i
Recn=0

If FSO. FileExists (FP & FN) =true Then
"//Read the introduction file to RecA (RECN):: Begin

Set f=fso.opentextfile (FilePath & FileName, 1)

Do as not F.atendofstream
Recn=recn+1
F.skipline
Loop
F.close

ReDim RecA (RECN)

Set f=fso.opentextfile (FilePath & FileName, 1)

I=0
Do as not F.atendofstream
RecA (i) =f.readline
I=i+1
Loop

F.close
Set f=nothing

"//Read the introduction file to RecA (RECN):: End
End If

If FSO. FileExists (FilePath & FileName) =true Then
Fso. DeleteFile (FilePath & FileName)
End If

Set f=fso.opentextfile (FilePath & FileName, 2, True)

'//write Introduction file
For I=0 to RecN-1
F.writeline (RecA (i))
Next

'//write to original file
For I=0 to RowN-1
F.writeline (Rowa (i))
Next

F.close
Set f=nothing

Read
End Sub

'//File Coalition
Public Sub Coalitafter (FP,FN)
Dim RECA,RECN
Dim F,i
Recn=0

If FSO. FileExists (FP & FN) =true Then
"//Read the introduction file to RecA (RECN):: Begin

Set f=fso.opentextfile (FilePath & FileName, 1)

Do as not F.atendofstream
Recn=recn+1
F.skipline
Loop
F.close

ReDim RecA (RECN)

Set f=fso.opentextfile (FilePath & FileName, 1)

I=0
Do as not F.atendofstream
RecA (i) =f.readline
I=i+1
Loop

F.close
Set f=nothing

"//Read the introduction file to RecA (RECN):: End
End If

If FSO. FileExists (FilePath & FileName) =true Then
Fso. DeleteFile (FilePath & FileName)
End If

Set f=fso.opentextfile (FilePath & FileName, 2, True)

'//write to original file
For I=0 to RowN-1
F.writeline (Rowa (i))
Next

'//write Introduction file
For I=0 to RecN-1
F.writeline (RecA (i))
Next

F.close
Set f=nothing

Read
End Sub

Private Sub Class_Initialize
Set fso=createobject ("Scripting.FileSystemObject")
End Sub
Private Sub Class_Terminate
Set fso=nothing
End Sub

End Class

%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.