<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
read="michael.txt"
'获取文件真实路径
read=LEFT(Server.MapPath(Request.ServerVariables("PATH_INFO")),InstrRev(Server.MapPath(Request.ServerVariables("PATH_INFO")),"\")) & read
'response.write "文件路径:" & read & "
" '输出文件真实路径
%>
<%if request.querystring("type")="crea" then%>
<%end if%>
<%if request.querystring("type")="add" then%>
<%end if%>
<%
if request.querystring("type")="edit" then
Set fs=CreateObject("Scripting.FileSystemObject")
if fs.FileExists(server.mappath("michael.txt")) then
Set ts=fs.OpenTextFile(server.mappath("michael.txt"))
%>
<%
else
response.write "找不到此文件"
end if
end if
%>
<%
if request.querystring("type")="crea" and request.form<>"" then '创建新的文件
Set fs=CreateObject("Scripting.FileSystemObject")
if fs.FileExists(server.mappath(request.form("T1")& ".txt")) then '判断文件是否存在
response.write ""
else
Set ts=fs.CreateTextFile(server.mappath(request.form("T1")& ".txt"),True)
ts.close
Set ts=fs.OpenTextFile(server.mappath(request.form("T1")& ".txt"),2,True)
ts.WriteLine(request.form("D1")) '写入文件内容 注:WriteLine是加入内容并换行,Write是加入内容不换行
ts.close
response.write ""
end if
set fs=nothing
end if
if request.querystring("type")="read" then '读取文件内容
Set fs=CreateObject("Scripting.FileSystemObject")
if fs.FileExists(server.mappath("michael.txt")) then '判断文件是否存在
Set ts=fs.OpenTextFile(server.mappath("michael.txt"))
response.write "文件内容: "
do until ts.AtEndOfStream '判断是否读到文件最后一行
response.write ts.readLine & "
" '读取文件逐行输出
loop
ts.close
else
response.write "找不到此文件"
end if
set fs=nothing
end if
if request.querystring("type")="add" and request.form<>"" then '添加文件内容
Set fs=CreateObject("Scripting.FileSystemObject")
if fs.FileExists(server.mappath("michael.txt")) then '判断文件是否存在
Set ts=fs.OpenTextFile(server.mappath("michael.txt"),8,True)
ts.WriteLine(request.form("D1")) '写入文件内容 注:WriteLine是加入内容并换行,Write是加入内容不换行
ts.close
response.write ""
else
response.write "找不到此文件"
end if
set fs=nothing
end if
if request.querystring("type")="edit" and request.form<>"" then '修改文件内容
Set fs=CreateObject("Scripting.FileSystemObject")
if fs.FileExists(server.mappath("michael.txt")) then '判断文件是否存在
Set ts=fs.OpenTextFile(server.mappath("michael.txt"),2,True)
ts.WriteLine(request.form("D1")) '写入文件内容 注:WriteLine是加入内容并换行,Write是加入内容不换行
ts.close
response.write ""
else
response.write "找不到此文件"
end if
set fs=nothing
end if
if request.querystring("type")="dele" then '删除文件
Set fs=CreateObject("Scripting.FileSystemObject")
if fs.FileExists(server.mappath("michael.txt")) then '判断文件是否存在
fs.DeleteFile server.mappath("michael.txt"),True
response.write ""
else
response.write "找不到此文件"
end if
set fs=nothing
end if
%>

