This Domain(Admin5.com) is for Sale:

FileSystemObject 示例代码

时间:2007-12-27  来源:不详  作者:林子
TextStream.Close Set TextStream = Folder.CreateTextFile("BathroomWindow.txt") TextStream.WriteLine("She Came In Through The Bathroom Window (by Lennon/McCartney)") TextStream.WriteLine("") TextStream.WriteLine("She came in through the bathroom window protected by a silver spoon") TextStream.WriteLine("But now she sucks her thumb and wanders by the banks of her own lagoon") TextStream.WriteBlankLines(2) TextStream.Close End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' GetLyrics ' 目的: ' 显示 lyrics 文件的内容。 ' 示范下面的内容 ' - FileSystemObject.OpenTextFile ' - FileSystemObject.GetFile ' - TextStream.ReadAll ' - TextStream.Close ' - File.OpenAsTextStream ' - TextStream.AtEndOfStream ' - TextStream.ReadLine '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function GetLyrics(FSO) Dim TextStream Dim S Dim File ' 有多种方法可用来打开一个文本文件,和多种方法来从文件读取数据。 ' 这儿用了两种方法来打开文件和读取文件: Set TextStream = FSO.OpenTextFile(TestFilePath & "\Beatles\OctopusGarden.txt", OpenFileForReading)

copyright dedecms


S = TextStream.ReadAll & NewLine & NewLine

TextStream.Close



Set File = FSO.GetFile(TestFilePath & "\Beatles\BathroomWindow.txt")

Set TextStream = File.OpenAsTextStream(OpenFileForReading)

Do While Not TextStream.AtEndOfStream

S = S & TextStream.ReadLine & NewLine

Loop

TextStream.Close



GetLyrics = S



End Function



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' BuildTestDirectory

' 目的: 

' 创建一个目录分层结构来示范 FileSystemObject' 以这样的次序来创建分层结构:

' C:\Test

' C:\TesteadMe.txt

' C:\Test\Beatles

' C:\Test\Beatles\OctopusGarden.txt

' C:\Test\Beatles\BathroomWindow.txt

' 示范下面的内容

'  - FileSystemObject.DriveExists

'  - FileSystemObject.FolderExists

'  - FileSystemObject.CreateFolder

'  - FileSystemObject.CreateTextFile

'  - Folders.Add

'  - Folder.CreateTextFile

'  - TextStream.WriteLine

'  - TextStream.Close

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



Function BuildTestDirectory(FSO)

看完这篇,您有何感觉呢?

上一篇:处理文件   下一篇:设计 FileSystemObject

文章评论

共有位Admini5网友发表了评论 查看完整内容