asp OpenTextFile文本讀取與寫入實例代碼
object.OpenTextFile(filename[, iomode[, create[, format]]])
參數(shù)
object :必選項。應(yīng)為 FileSystemObject 對象的名稱。
filename :必選項。字符串表達式,指明要打開的文件名稱。
iomode :可選項。輸入/輸出模式,是下列三個常數(shù)之一:ForReading,F(xiàn)orWriting,或 ForAppending。
create :可選項。Boolean 值,指出當指定的 filename 不存在時是否能夠創(chuàng)建新文件。允許創(chuàng)建新文件時為 True,否則為 False。默認值為 False。
format :可選項。三個 Tristate 值之一,指出以何種格式打開文件。若忽略此參數(shù),則文件以 ASCII 格式打開。
設(shè)置
iomode 參數(shù)可為下列設(shè)置之一:
常數(shù) 值 描述
ForReading 1 以只讀模式打開文件。不能對此文件進行寫操作。
ForWriting 2 以只寫方式打開文件。不能對此文件進行讀操作。
ForAppending 8 打開文件并在文件末尾進行寫操作。
format 參數(shù)可為下列設(shè)置之一:
常數(shù) 值 描述
TristateUseDefault -2 以系統(tǒng)默認格式打開文件。
TristateTrue -1 以 Unicode 格式打開文件。
TristateFalse 0 以 ASCII 格式打開文件。
說明
以下代碼舉例說明如何使用 OpenTextFile 方法打開寫文件:
Sub OpenTextFileTest
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
f.Write "嗨,你好!"
f.Close
End Sub
腳本之家寫的一個判斷文件是否被更改過的代碼
Dim fso Set fso = CreateObject("Scripting.FileSystemObject") set fn2=fso.GetFile("E:\webroot\jb51\index2.htm") flsize2=fn2.size fldate2=fn2.datelastmodified set fn=fso.GetFile("E:\webroot\jb51\index.htm") flsize1=fn.size fldate1=fn.datelastmodified If fso.FileExists("E:\webroot\jb51\index2.htm") and flsize2>50000 and fldate2>fldate1 Then '判斷文件的大小,如果html文件重新生成需要判斷是否更新過且文件不能小于50K fso.getfile("E:\webroot\jb51\index2.htm").copy("E:\webroot\jb51\index.htm") if err.number=0 then WriteHistory "成功"&now()&".........","log.txt" end if '日志寫入函數(shù) Sub WriteHistory(hisChars, path) Const ForReading = 1, ForAppending = 8 Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(path, ForAppending, True) f.WriteLine hisChars f.Close End Sub
相關(guān)文章
access數(shù)據(jù)庫的一些少用操作,ASP,創(chuàng)建數(shù)據(jù)庫文件,創(chuàng)建表,創(chuàng)建字段,ADOX
access數(shù)據(jù)庫的一些少用操作,ASP,創(chuàng)建數(shù)據(jù)庫文件,創(chuàng)建表,創(chuàng)建字段,ADOX...2006-10-10利用ASP從遠程服務(wù)器上接收XML數(shù)據(jù)的方法
利用ASP從遠程服務(wù)器上接收XML數(shù)據(jù)的方法...2007-01-01比較不錯的asp模板引終極講解(WEB開發(fā)之ASP模式)
比較不錯的asp模板引終極講解(WEB開發(fā)之ASP模式)...2007-08-08utf-8 網(wǎng)頁不顯示+utf-8網(wǎng)頁亂碼的通用解決方法
當我們在瀏覽或使用uft-8格式的頁面的時候,總有可能出現(xiàn)一些亂碼或不顯示的問題,下載就瀏覽器客戶端和服務(wù)器都有一些原因的分析與解決方法2008-10-10