VBscript+Asp脚本(14)
2011年07月15日
----------------------------------------------------------------
"
Next
ShowFolderList=s
End Function
%>
------------------------------------------------------------------
--------------------------------------------------------------------
---------------------------------------------------------------------
Const ForReading=1,ForWriting=2,ForAppending=8
Const TristateUseDefault=-2,TristateTrue=-1,TristateFalse=0
dim fso,f,ts
Set fso=CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile "test1.txt"
Set f=fso.GetFile("test1.txt")
Set ts=f.OpenAsTextStream(ForWriting,TristateUseDefault)
ts.Write "嗨,你好!"
ts.Close
Set ts=f.OpenAsTextStream(ForReading,TristateUseDefault)
TextStreamTest=ts.ReadLine
ts.Close
End Function
%>
-------------------------------------------------------------------------
Const ForReading=1,ForWriting=2,ForAppending=8
Const TristateUseDefault=-2,TristateTrue=-1,TristateFalse=0
dim fso,f,ts
Set fso=CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile "test1.txt"
Set f=fso.GetFile("test1.txt")
Set ts=f.OpenAsTextStream(ForWriting,TristateUseDefault)
ts.Write "嗨,你好!"
ts.Close
Set ts=f.OpenAsTextStream(ForReading,TristateUseDefault)
TextStreamTest=ts.ReadLine
ts.Close
End Function
%>
--------------------------------------------------------------------------
----------------------------------------------------------------------------
使用File对象得到文件的信息
sub cmdGetInfo_OnClick()
GetFileInfo(document.frmFile.file1.value)
end sub
sub GetFileInfo(filepath)
dim fs,f,s
Set fs=CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile(filepath)
s="该文件的创建时间是:"&f.DateCreated
s=s&chr(10)&"上次修改时间是:"&f.DateLastModified
s=s&chr(10)&"文件大小为:"&f.Size
s=s&chr(10)&"文件路径为:"&f.Path
alert s
end sub
-------------------------------------------------------------------------
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 "使用Read方法读取文件中指定数目的字符!"
Set f=fso.OpenTextFile("c:\testfile.txt",ForReading)
ReadTextFile=f.Read(8)
End Function
%>
--------------------------------------------------------------------------
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 "使用Read方法读取文件中指定数目的字符!"
Set f=fso.OpenTextFile("c:\testfile.txt",ForReading)
f.Skip(6)
ReadTextFile=f.ReadLine
End Function
%>
-----------------------------------------------------------------------------
Const ForReading=1,ForWriting=2
dim fso,f
Set fso=CreateObject("Scripting.FileSystemObject")
Set f=fso.OpenTextFile("c:\testfile.txt",ForWriting,True)
f.Write "VBScript脚本很有趣!"&vbCrLf&"你想学会它吗?"
Set f=fso.OpenTextFile("c:\testfile.txt",ForReading)
f.SkipLine
SkipLineInFile=f.ReadLine
End Function
%>
-------------------------------------------------------------------------------
Const ForReading=1,ForWriting=2
dim fso,f
Set fso=CreateObject("Scripting.FileSystemObject")
Set f=fso.OpenTextFile("c:\testfile.txt",ForWriting,True)
f.Write "使用Write方法在文件中写入字符。"
Set f=fso.OpenTextFile("c:\testfile.txt",ForReading)
WriteToFile=f.ReadLine
End Function
%>
2011年07月15日
----------------------------------------------------------------
"
Next
ShowFolderList=s
End Function
%>
------------------------------------------------------------------
--------------------------------------------------------------------
---------------------------------------------------------------------
Const ForReading=1,ForWriting=2,ForAppending=8
Const TristateUseDefault=-2,TristateTrue=-1,TristateFalse=0
dim fso,f,ts
Set fso=CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile "test1.txt"
Set f=fso.GetFile("test1.txt")
Set ts=f.OpenAsTextStream(ForWriting,TristateUseDefault)
ts.Write "嗨,你好!"
ts.Close
Set ts=f.OpenAsTextStream(ForReading,TristateUseDefault)
TextStreamTest=ts.ReadLine
ts.Close
End Function
%>
-------------------------------------------------------------------------
Const ForReading=1,ForWriting=2,ForAppending=8
Const TristateUseDefault=-2,TristateTrue=-1,TristateFalse=0
dim fso,f,ts
Set fso=CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile "test1.txt"
Set f=fso.GetFile("test1.txt")
Set ts=f.OpenAsTextStream(ForWriting,TristateUseDefault)
ts.Write "嗨,你好!"
ts.Close
Set ts=f.OpenAsTextStream(ForReading,TristateUseDefault)
TextStreamTest=ts.ReadLine
ts.Close
End Function
%>
--------------------------------------------------------------------------
----------------------------------------------------------------------------
使用File对象得到文件的信息
sub cmdGetInfo_OnClick()
GetFileInfo(document.frmFile.file1.value)
end sub
sub GetFileInfo(filepath)
dim fs,f,s
Set fs=CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile(filepath)
s="该文件的创建时间是:"&f.DateCreated
s=s&chr(10)&"上次修改时间是:"&f.DateLastModified
s=s&chr(10)&"文件大小为:"&f.Size
s=s&chr(10)&"文件路径为:"&f.Path
alert s
end sub
-------------------------------------------------------------------------
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 "使用Read方法读取文件中指定数目的字符!"
Set f=fso.OpenTextFile("c:\testfile.txt",ForReading)
ReadTextFile=f.Read(8)
End Function
%>
--------------------------------------------------------------------------
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 "使用Read方法读取文件中指定数目的字符!"
Set f=fso.OpenTextFile("c:\testfile.txt",ForReading)
f.Skip(6)
ReadTextFile=f.ReadLine
End Function
%>
-----------------------------------------------------------------------------
Const ForReading=1,ForWriting=2
dim fso,f
Set fso=CreateObject("Scripting.FileSystemObject")
Set f=fso.OpenTextFile("c:\testfile.txt",ForWriting,True)
f.Write "VBScript脚本很有趣!"&vbCrLf&"你想学会它吗?"
Set f=fso.OpenTextFile("c:\testfile.txt",ForReading)
f.SkipLine
SkipLineInFile=f.ReadLine
End Function
%>
-------------------------------------------------------------------------------
Const ForReading=1,ForWriting=2
dim fso,f
Set fso=CreateObject("Scripting.FileSystemObject")
Set f=fso.OpenTextFile("c:\testfile.txt",ForWriting,True)
f.Write "使用Write方法在文件中写入字符。"
Set f=fso.OpenTextFile("c:\testfile.txt",ForReading)
WriteToFile=f.ReadLine
End Function
%>