• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Read and write into a DB text file

Hi,
I have two text files text1.txt and text2.dat
Text1.txt contains data which i would like to manipulate and then write the modifications to text2.dat

How do I read line for line in text1.txt modify the string and than write it line for line to text2.dat? Do not worry about the the modification bit, I know how to do that. I am only interested in the reading and wrting part.

Thanks
0
LotharGores
Asked:
LotharGores
  • 2
1 Solution
 
sybeCommented:
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
Set oReadFile = oFS.OpenTextFile("C:\temp\readfile.txt")
Set oWriteFile = oFs.OpenTextFile("C:\temp\writefile.txt",8)
Do While Not oReadFile.AtEndOfStream
    sLine = oReadFile.ReadLine
    oWriteFile.WriteLine(sLine)
Loop
oReadFile.Close: Set oReadFile = Nothing
oWriteFile.Close: Set oWriteFile = Nothing
Set oFs = Nothing
0
 
LotharGoresAuthor Commented:
Hi sybe,
can you provide me with some code to check "writefile.txt" exists - and if not to create it!

thanks for the above code works just fine!
0
 
sybeCommented:
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
Set oReadFile = oFS.OpenTextFile("C:\temp\readfile.txt")
If Not oFS.FileExists("C:\temp\writefile.txt") Then oFs.CreateTextFile("C:\temp\writefile.txt")
Set oWriteFile = oFs.OpenTextFile("C:\temp\writefile.txt",8)


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now