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)
%>