繁体中文
设为首页
加入收藏
当前位置:ASP技术首页 >> ASP基础 >> FileSystemObject组件新建\读取\添加\修改\删除功能实例

FileSystemObject组件新建\读取\添加\修改\删除功能实例

2006-07-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介: FileSystemObject组件应该实例

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

FileSystemObject组件应该实例

<%

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%>

请输入文件名 : .txt

请输入文件内容:

<%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

%>

责任编辑:admin
相关文章