3ws.ezer.com 9/7/2010 12:25:58 PM 3ws.ezer.com:ASP:file create-and-naming:学习 asp sql html code in 简体中文

web tools rank checker

domain .cn
.net .cn .com.cn
你正在阅览 :: 简体中文:: 学习 ASP SQL VB HTML code

学习 .ASP SQL HTML XML CSS JAVA Perl code study
English Chinese_Traditional Chinese_Simplified

你正在阅览 :: 简体中文 Chinese_Simplified

学习.主题:
首页
ASP
. Active-Server-Flash
. Array
. Cache
. Connection
. Count
. Counter
. Distinct
. Email
. File
»Create
»create-and-naming
»delete
»File-obj-Count
»Move
»ReadAll-ReadLine
»Server.MapPath
. Folder
. Function
. GetSQLserver
. Header
. mySQL
. Record
. Recordset
. Request
. Response
. Server
. server-createobject
. ServerVariables
. Session
. Special-Symbols
. String
. Sub
. Time
CSS
Ecommerce
HTML
InternetProtocol
JAVA
Microsoft
php
Robots
SearchEngine
SQL
SQLserver
VBscript
XML

SiteMap

3w....学习.教学 > ASP > file » create-and-naming

3w learning

file >
create-and-naming

Title:

Creating and Naming a Text File


Description:

1. Create an instance of the FileSystemObject. 2. Set a variable named strPath to the folder where the file will be created (C:\FSO). 3. Use the GetTempName method to generate a unique file name. 4. Use the BuildPath method to combine the folder name and file name and create a full path for the temporary file. The full path is stored in the variable strFullName. 5. Call the CreateTextFile method, using strFullName as the method parameter. 6. Close the file immediately after creating it. In a production environment, you would most likely write data to the file before closing it.


Example Code:

Set objFSO = CreateObject("Scripting.FileSystemObject") strPath = "C:\FSO" strFileName = objFSO.GetTempName strFullName = objFSO.BuildPath(strPath, strFileName) Set objFile = objFSO.CreateTextFile(strFullName) objFile.Close 1. Create an instance of the FileSystemObject. 2. Use the OpenTextFile method to open the text file. The OpenTextFile method requires two parameters: the path to the file and one of the following values: • For reading (parameter value = 1, constant = ForReading). Files opened in this mode can only be read from. To write to the file, you must open it a second time by using either the ForWriting or ForAppending mode. • For writing (parameter value 2, constant = ForWriting). Files opened in this mode will have new data replace any existing data. (That is, existing data will be deleted and the new data added.) Use this method to replace an existing file with a new set of data. • For appending (parameter value 8, constant = ForAppending). Files opened in this mode will have new data appended to the end of the file. Use this method to add data to an existing file. You must use the appropriate parameter when opening the file. For example, if you open a file for reading and then attempt to write to the file, you will receive a "Bad file mode" error. You will also receive this error if you attempt to open anything other than a plain-text file. (It is worth noting that both HTML and XML files are plain-text files.) You can use either the parameter value (for example, 1 for reading) or you can create a constant and set the value appropriately. For example, both of these methods will open a file for reading: Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\FSO\ScriptLog.txt", ForReading) Set objFile2 = objFSO.OpenTextFile("C:\FSO\ScriptLog2.txt", 1) However, you cannot use the constants without first defining them. This is due to the fact that VBScript does not have intrinsic access to COM object constants. The following script sample will fail and return an "Invalid procedure call or argument" error because the ForReading constant has not been explicitly defined. Because it has not been defined, ForReading is automatically assigned the value 0, and 0 is not a valid parameter for OpenTextFile. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\FSO\ScriptLog.txt", ForReading) The script in Listing 4.35 opens C:\FSO\ScriptLog.txt for reading, using the user-defined constant ForReading to represent the value 1. Listing 4.35 Opening a Text File for Reading 1 2 3 Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\FSO\ScriptLog.txt", ForReading)


Example Result:


The '8' in the following line is the mode: Set f=fso.OpenTextFile(Server.MapPath("mynote.txt"),8,true) mode 1 is ForReading mode 2 is ForWriting and mode 8 is ForAppending The 'true' paramater is saying to create the file if it doesn't already exist. Other methods of the textstream object (objFile), depending on the mode are: objFile.Write(string) objFile.Read(length) objFile.ReadAll objFile.ReadLine


..
...
...

[ 9/7/2010 ]

www learning school add more scripts and tips memo
You are at >>3WS.EZER.COM >> 3WS.EZER.COM/ASP/FILE/CREATE-AND-NAMING.ASP>>ASP
Helpful link:: SEO web tools :: Live PR | SERP checker Google SERP pageranking checker
back to top Ezer code adding :: Questions ;email