亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

asp OpenTextFile文本讀取與寫入實例代碼

 更新時間:2008年08月09日 20:54:37   投稿:mdxy-dxy  
打開指定的文件并返回一個 TextStream 對象,可以讀取、寫入此對象或?qū)⑵渥芳拥轿募?

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 方法打開寫文件:

復(fù)制代碼 代碼如下:

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)文章

最新評論