asp(vbs)fso OpenTextFile方法参数说明 |
||||||||||||||||||||||||
本文标签:fso,OpenTextFile OpenTextFile是asp语言中的一个方法 1、方法编辑打开指定的文件并返回一个 TextStream 对象,可以通过这个对象对文件进行读、写或追加 。 必选项 。 object 应为 FileSystemObject 的名称 。 3、设置编辑iomode 参数可以是下列设置中的任一种: 常数 值 描述 ForReading 1 以只读方式打开文件 。 不能写这个文件 。 format 参数可以是下列设置中的任一种: TristateTrue 以 Unicode 格式打开文件 。 4、说明编辑下面的代码说明了如何使用 OpenTextFile 方法打开文件并追加文本: 在vbs脚本中的用例 打开指定的文件并返回一个TextStream对象,可以读取、写入此对象或将其追加到文件 。 iomode参数可为下列设置之一:
用法举例: 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:\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 日志写入函数 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 |