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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-17 我要评论
想了解asp OpenTextFile文本读取与写入实例代码的相关内容吗,在本文为您仔细讲解asp OpenTextFile的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:asp,OpenTextFile,文本,下面大家一起来学习吧。

object.OpenTextFile(filename[, iomode[, create[, format]]]) 
参数 
object :必选项。应为 FileSystemObject 对象的名称。 
filename :必选项。字符串表达式,指明要打开的文件名称。 
iomode :可选项。输入/输出模式,是下列三个常数之一:ForReading,ForWriting,或 ForAppending。 
create :可选项。Boolean 值,指出当指定的 filename 不存在时是否能够创建新文件。允许创建新文件时为 True,否则为 False。默认值为 False。 
format :可选项。三个 Tristate 值之一,指出以何种格式打开文件。若忽略此参数,则文件以 ASCII 格式打开。
设置 
iomode 参数可为下列设置之一: 
常数                 值                        描述 
ForReading        1         以只读模式打开文件。不能对此文件进行写操作。 
ForWriting         2         以只写方式打开文件。不能对此文件进行读操作。 
ForAppending    8         打开文件并在文件末尾进行写操作。 
format 参数可为下列设置之一: 
常数                              值              描述 
TristateUseDefault           -2        以系统默认格式打开文件。 
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
'日志写入函数
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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们