FileSystemObject component usage example

Source: Internet
Author: User

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

'Createlyrics

'Purpose:

'Create two text files in the folder.

'Demonstrate the following content

'-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 this statement does not wrap into a file.

Textstream. writeline ("(by Ringo Starr )")

Textstream. writeblanklines (1)

Textstream. writeline ("I 'd like to be under the sea in an octopus 'garden in the shade ,")

Textstream. writeline ("he 'd let us in, knows where we 've ve been -- in his Octopus 'garden in the shade .")

Textstream. writeblanklines (2)

Textstream. Close

Set textstream = folder. createtextfile ("bathroomworkflow workflow 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

'Purpose:

'Displays the content of the lyrics file.

'Demonstrate the following content

'-FileSystemObject. opentextfile

'-FileSystemObject. GetFile

'-Textstream. readall

'-Textstream. Close

'-File. openastextstream

'-Textstream. atendofstream

'-Textstream. Readline

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

Function getlyrics (FSO)

Dim textstream

Dim s

Dim File

'You can use multiple methods to open a text file and read data from the file.

'Here we use two methods to open and read files:

Set textstream = FSO. opentextfile (testfilepath & "\ Beatles \ octopusgarden.txt", openfileforreading)

S = textstream. readall & newline

Textstream. Close

Set file = FSO. GetFile (testfilepath & "\ Beatles \ bathroom1_txt ")

Set textstream = file. openastextstream (openfileforreading)

Do while 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.