asp(vbs)fso OpenTextFile方法参数说明

2019-04-01 12:12:57于海丽
以只读模式打开文件。不能对此文件进行写操作。 ForWriting 2 以只写方式打开文件。不能对此文件进行读操作。 ForAppending 8 打开文件并在文件末尾进行写操作。


  format参数可为下列设置之一:

常数 描述
TristateUseDefault -2 以系统默认格式打开文件。
TristateTrue -1 以Unicode格式打开文件。
TristateFalse 0 以ASCII格式打开文件。

用法举例:

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

易采站长站写的一个函数

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
set fn2=fso.GetFile("E:webrootjb51index2.htm")
flsize2=fn2.size
fldate2=fn2.datelastmodified
set fn=fso.GetFile("E:webrootjb51index.htm")
flsize1=fn.size
fldate1=fn.datelastmodified
If fso.FileExists("E:webrootjb51index2.htm") and flsize2>50000 and fldate2>fldate1 Then
'判断文件的大小,如果html文件重新生成需要判断是否更新过且文件不能小于50K
fso.getfile("E:webrootjb51index2.htm").copy("E:webrootjb51index.htm")
if err.number=0 then WriteHistory "成功"&now()&".........","log.txt"
end if
'日志写入函数
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

您可能感兴趣的文章:

asp OpenTextFile文本读取与写入实例代码