<%@ Language=VBScript %> <% '######################################################## '## ## '## Anil Kumar - for www.ddrcgroup.com November 2001 ## '## alpha_kappa@rediffmail.com ## '## makrisoft.cjb.net | anilkumar.itgo.com ## '## ## '######################################################## const ForReading=1,ForWriting=2,ForAppending=8 pageURL=Request.QueryString("from") 'do nothing if there is no page URL - so that blank entries are not created. If pageURL="" then Response.End() StrBuf="0" dim strpos dim PthStr PthStr = Server.MapPath("../../db/stat.txt") set fso = Server.CreateObject("Scripting.FileSystemObject") 'read information in file set tfile = fso.OpenTextFile(PthStr,ForReading,True) If not tfile.AtEndOfStream then StrBuf=tfile.readall end if tfile.Close set tfile = nothing 'now check if the page name has an existing entry and 'then update the entry If checkfor(StrBuf,pageURL)=1 then call writeinfo() end if set fso=nothing '####################### '## related functions ## '####################### sub writeinfo() 'write information to file set tfile=fso.OpenTextFile(PthStr,ForWriting,True) 'find the count and increment it pos1=InStr(strpos+2,StrBuf,vbcrlf) pos2=Instr(pos1+1,StrBuf,vbcrlf) strlength=pos2-pos1-1 strnum=""&Clng(Mid(StrBuf,pos1+1,strlength)) Count=""&(Clng(strnum)+1) 'now generate a new string with updated count StrBuf=Left(StrBuf,pos1)&replace(StrBuf,strnum,Count,pos1+1,1) 'write updated information to text file tfile.write StrBuf tfile.Close set tfile=nothing end sub function checkfor(str,url) 'checks for file name using a regular expression dim reg,Match,Matches set reg=New RegExp 'enclose url with newlines to create unique string oldurl=url url=vbcrlf&url&vbcrlf reg.Pattern=url reg.IgnoreCase=True reg.Global=True set Matches=reg.Execute(str) for each Match in Matches strpos=Match.FirstIndex checkfor=1 exit function next 'no matches found, so create new entry in file call createnew(oldurl) end function function createnew(oldurl) set tfile=fso.OpenTextFile(PthStr,ForReading,False) If not tfile.AtEndOfStream then Addtext=tfile.readall else Addtext="" end if tfile.close Addtext=Addtext&oldurl&vbcrlf&"1"&vbcrlf ' ideally you could add some code to insert a newline character as the first ' character of the file, if it is not already so, but I have omitted it ' since you could just create a textfile manually with a newline character - ' all you have to do is start writing from the second line - can avoid unnecessary ' code. set tfile=fso.OpenTextFile(PthStr,ForWriting,False) tfile.write(Addtext) tfile.close set tfile=nothing end function '######################################################### '## sample data in stat.txt-the first filename starts ## '## is preceded by a newline character so that every ## '## filename is enclosed by newline characters ## '######################################################### '## ## '## about.htm ## '## 3 ## '## index.htm ## '## 5 ## '## contact.htm ## '## 8 ## '######################################################### %>