Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use txt file

Status
Not open for further replies.

lamber

Programmer
Joined
Nov 19, 2003
Messages
7
Location
PT
I need a vbscript that read from file a.txt, and then write in file b.txt.

Best regards.
 
Feel free to do a keyword search in this forum for
Code:
 FileSystemObject
or
Code:
 fso

Hope This Help
PH.
 
lamber

This script reads from one text file and writes back to the same file. It is well commented and should get you off to a good start.

<% Option Explicit %>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<html>
<head>
<title>File Incrementer</title>


</head>

<body >

<H2 align=&quot;center&quot;>File Incrementer</h2>

<%
'Dimension the variables
Dim txtFileObj ' As a file object
Dim objFSO ' As a FileSystemObject
Dim filePath ' As a logical path to the file
Dim TextStreamObj ' As a text stream object
Dim longIntCount ' As a long integer count variable

'Define constants
Const fileName = &quot;asp_count.txt&quot; 'file to read & write to

' Create a filesystem object
Set objFSO = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

'Map the logical path to the physical path
filePath = Server.MapPath(fileName)

'Initialise the File Object with the path and name of the text file
Set txtFileObj = objFSO.GetFile(filePath)

'Create a TextStream Object to read, create, and write to the text file
Set TextStreamObj = txtFileObj.OpenAsTextStream

'Read in the number from the text file, convert it to long integer data type
'and save it in a variable.
longIntCount = CLng(TextStreamObj.ReadAll)

'Increment the count variable
longIntCount = longIntCount + 1

'Overwrite the original text file with a new counter file
Set TextStreamObj = objFSO.CreateTextFile(filepath)

'Write the new number into the counter file
TextStreamObj.Write CStr(longIntCount)

'Release server resources
Set objFSO = Nothing
Set TextStreamObj = Nothing
Set txtFileObj = Nothing

Response.Write(&quot;<br>The count is &quot; & longIntCount)
%>

<br>
This file is read by another <A href=&quot;File Reader.asp&quot;>page</a> too!

<br><br>

</body>
</html>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top