FileSystemObject組件建立\讀取\添加\修改\刪除功能執行個體

來源:互聯網
上載者:User
filesystemobject <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>FileSystemObject組件應該執行個體</title>
</head>

<body>
<input name="B0" type="button" value="建立文字檔" onClick="window.location='test1.asp?type=crea'">
<input name="B1" type="button" value="讀取檔案內容" onClick="window.location='test1.asp?type=read'">
<input name="B2" type="button" value="添加檔案內容" onClick="window.location='test1.asp?type=add'">
<input name="B3" type="button" value="修改檔案內容" onClick="window.location='test1.asp?type=edit'">
<input name="B4" type="button" value="刪除檔案內容" onClick="window.location='test1.asp?type=dele'">
<%
read="michael.txt"
'擷取檔案真實路徑
read=LEFT(Server.MapPath(Request.ServerVariables("PATH_INFO")),InstrRev(Server.MapPath(Request.ServerVariables("PATH_INFO")),"\")) & read
'response.write "檔案路徑:" & read & "<br>" '輸出檔案真實路徑
%>
<hr>
<%if request.querystring("type")="crea" then%>
<form action="test1.asp?type=crea" method="post" name="form1">
請輸入檔案名稱 : <input name="T1" size="45">.txt<br>
請輸入檔案內容:<textarea name="D1" cols="50" rows="5"></textarea>
<input name="bu" type="Submit" value="提交">
</form>
<%end if%>
<%if request.querystring("type")="add" then%>
<form action="test1.asp?type=add" method="post" name="form1">
<textarea name="D1" cols="70" rows="5"></textarea>
<input name="bu" type="Submit" value="提交">
</form>
<%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"))
%>
<form action="test1.asp?type=add" method="post" name="form1">
<textarea name="D1" cols="70" rows="5"><%=ts.ReadLine%></textarea>
<input name="bu" type="Submit" value="提交">
</form>
<%
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 "<script>alert('該檔案已經存在');window.location='test1.asp?type=crea';</script>"
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 "<script>alert('建立檔案成功');window.location='test1.asp?type=read';</script>"

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 & "<br>" '讀取檔案逐行輸出
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.Fi



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。