Examples of usage of FileSystemObject components

Source: Internet
Author: User
filesystemobject| example ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' "" "" "" "" "" "" "" "" "" "" "" ""
' Createlyrics
Objective
' Create two text files in the folder.
' Demonstrate the content below
'-Filesystemobject.createtextfile
'-Textstream.writeline
'-Textstream.write
'-Textstream.writeblanklines
'-Textstream.close
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub Createlyrics (Folder)

Dim TextStream

Set TextStream = Folder.createtextfile ("OctopusGarden.txt")

Textstream.write ("Octopus ' Garden") ' Note that the statement does not add line wrapping to the file.
Textstream.writeline ("(by Ringo Starr)")
Textstream.writeblanklines (1)
Textstream.writeline ("I ' d" as "under" The Sea in a octopus ' garden in the Shade, ")
Textstream.writeline ("He's d let us in, knows where we ' ve been--in his octopus ' garden in the shade.")
Textstream.writeblanklines (2)

Textstream.close

Set TextStream = Folder.createtextfile ("BathroomWindow.txt")
Textstream.writeline ("She came in through" 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
Objective
' Displays the contents of the lyrics file.
' Demonstrate the content below
'-Filesystemobject.opentextfile
'-Filesystemobject.getfile
'-Textstream.readall
'-Textstream.close
'-File.openastextstream
'-Textstream.atendofstream
'-Textstream.readline
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function Getlyrics (FSO)

Dim TextStream
Dim S
Dim File

' There are a number of ways to open a text file, and a variety of ways to read data from a file.
' Here are two ways to open files and read files:

Set TextStream = FSO. OpenTextFile (Testfilepath & "\beatles\octopusgarden.txt", openfileforreading)

S = textstream.readall & newline & newline
Textstream.close

Set File = FSO. GetFile (Testfilepath & "\beatles\bathroomwindow.txt")
Set TextStream = File.openastextstream (openfileforreading)
Do as not Textstream.atendofstream
s = S & textstream.readline & NewLine
Loop
Textstream.close

Getlyrics = S

End Function



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.