FSO - Amending a line in a text file

Results 1 to 5 of 5

Thread: FSO - Amending a line in a text file

  1. #1
    Join Date
    Dec 1969
    Posts
    905

    Default FSO - Amending a line in a text file

    Does anyone know how (or a good article about) to amend a line in an existing text file using FSO?<BR><BR>For example if I have the file text.txt with the following lines:-<BR><BR>Line1, Monkey, Magic<BR>Line2, Starsky, Hutch<BR>Line3, Uncle, Man from<BR><BR>How could I access the file and replace line 2 specifically?<BR><BR>All the examples I have found either in books or on web just deal with appending to the end of a file.<BR><BR>Thanks<BR><BR>Matt

  2. #2
    Join Date
    Dec 1969
    Posts
    16,931

    Default Two ways:

    Either:<BR>1) Read in, and then iterate through, the file contents until you find the line you want, or<BR>2) Treat the file as a database and connect to it using ODBC - then you can just use an UPDATE statement.<BR><BR>Craig.

  3. #3
    Join Date
    Dec 1969
    Posts
    1,913

    Default ODBC - nice idea :) <eop>

    .

  4. #4
    Join Date
    Dec 1969
    Posts
    16,931

    Default Depends, of course, on the file content...

    Does he have a unique identifier (I assume he must, or he&#039;ll have nothing to search for)?<BR><BR>Also, I&#039;m not sure exactly how efficient it is. Surely much more efficient than alternative 1 on large text files, but I&#039;m not sure how efficient if the system is quite small.<BR><BR>Also, he&#039;ll have to look up how to actually do it. I read something (4guys, I think) a while ago, but never had to do it.<BR><BR>Craig.


  5. #5
    Join Date
    Dec 1969
    Posts
    905

    Default RE: Depends, of course, on the file content...

    I have tried the ODBC route once before and managed to create a mock relational database structure using csv files in a dir. Couldn&#039;t think of a practical use for it at the time as it was just done out of curiosity and to be honest I&#039;d forgotten about it until you mentioned it.<BR><BR>The text file itself isn&#039;t huge (50 lines or so) so I&#039;ll try your first option.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •