ASP FSO如何把数据写入到TXT的第一行而不是最后一行
'在文件结尾插入一行functionFSOappline(filename,Linecontent)dimfso,fsetfso=server.CreateObject(...
'在文件结尾插入一行
function FSOappline(filename,Linecontent)
dim fso,f
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),8,1)
f.write chr(13)&chr(10)&Linecontent
f.close
set f = nothing
end function
record = getip()
if FSOgetContent("getIp.txt") <> "" then
if instr(FSOgetContent("getIp.txt"),record) = 0 then
FSOappline "getIp.txt",record
end if
else
FSOappline "getIp.txt",record
end if
response.write("IP已记录")
response.End()
%>set f = fso.opentextfile(server.mappath(filename),8,1) 这个是写入最后一行
set f = fso.opentextfile(server.mappath(filename),2,1) 这个写入后之前的数据都会被清除
写入最后一行后在移动到第一行有没有可能 展开
function FSOappline(filename,Linecontent)
dim fso,f
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),8,1)
f.write chr(13)&chr(10)&Linecontent
f.close
set f = nothing
end function
record = getip()
if FSOgetContent("getIp.txt") <> "" then
if instr(FSOgetContent("getIp.txt"),record) = 0 then
FSOappline "getIp.txt",record
end if
else
FSOappline "getIp.txt",record
end if
response.write("IP已记录")
response.End()
%>set f = fso.opentextfile(server.mappath(filename),8,1) 这个是写入最后一行
set f = fso.opentextfile(server.mappath(filename),2,1) 这个写入后之前的数据都会被清除
写入最后一行后在移动到第一行有没有可能 展开
1个回答
展开全部
你可以先把文件的全部内容读出来,然后把你要写入的数据放到读出内容的前面或后面,合为一个大字符串,然后再一次性用覆盖模式写入到原文件中即可。比如:
function FSOappline(filename,Linecontent)
dim fso,f,s
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1,1)
s=f.readall
f.close
set f = fso.opentextfile(server.mappath(filename),2,1)
f.write s & vbcrlf & Linecontent '这个是写到最后一行
'f.write Linecontent & vbcrlf & s '改为这个则是写到第一行
f.close
set f = nothing
set fso = nothing
end function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询