|
OpenTextFile是asp語言中的一個方法 1、方法編輯打開指定的文件并返回一個 TextStream 對象,可以通過這個對象對文件進(jìn)行讀、寫或追加。 必選項。 object 應(yīng)為 FileSystemObject 的名稱。 3、設(shè)置編輯iomode 參數(shù)可以是下列設(shè)置中的任一種: 常數(shù) 值 描述 ForReading 1 以只讀方式打開文件。 不能寫這個文件。 format 參數(shù)可以是下列設(shè)置中的任一種: TristateTrue 以 Unicode 格式打開文件。 4、說明編輯下面的代碼說明了如何使用 OpenTextFile 方法打開文件并追加文本: 在vbs腳本中的用例 打開指定的文件并返回一個TextStream對象,可以讀取、寫入此對象或?qū)⑵渥芳拥轿募?br>
object.OpenTextFile(filename[,iomode[,create[,format]]]) iomode參數(shù)可為下列設(shè)置之一:
用法舉例: 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
Call OpenTextFileTest
腳本之家寫的一個函數(shù) 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
您可能感興趣的文章: |
|
|