FSO Use tutorial 5--How to create a new file using the FSO

Source: Internet
Author: User
Tags file copy
fso| Create | tutorials

How to use the FSO to create a new file-fso tutorial 5

After understanding the file copy, delete, move, and rename, let's learn how to access the data in the file. The TextStream object that must be used for file access is a FileSystemObject child object. The method has two kinds of opentextfile and createtextfile, the use example is as follows:

' first set up the FileSystemObject object
Set fs = Server.CreateObject ("Scripting.FileSystemObject")
' Create a TextStream type Object again
Set txt = fs. OpenTextFile (Parameter ...)


Or:

Set fs = Server.CreateObject ("Scripting.FileSystemObject")
Set txt = fs. CreateTextFile (Parameter ...)
After we have established the TextStream object, we can then invoke the ReadLine, WriteLine, Read, ReadAll, Write ... that are attached to the TextStream object. and other methods to access the contents of the file.

V. How to create a file with the FSO:

Method: CreateTextFile

Call Format:

CreateTextFile (file [, overwrite original file])


Precautions:

The "Overwrite the original file" parameter is valid when the file you want to create is already present. When a file already exists and the parameter is set to False, a "file exists" error ( error encoded =58) is generated, and if the parameter is set to TRUE or omitted, the original file is overwritten.

SOURCE Example:

<%
'================================================
' Author: Arisisi
' URL: http://www.alixixi.com/
' Source: FSO move file, rename file example
' Time: December 17, 2005
'================================================
Set fs = Server.CreateObject ("Scripting.FileSystemObject")
File = Server.MapPath ("File1.txt")

' Create a new file File1.txt and must be a nonexistent file
Set txt = fs. CreateTextFile (File,false)

' Create a new file File1.txt, packages file exists then overwrite
Set txt = fs. CreateTextFile (File)
%>



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.