New call-to-action
Results 1 to 4 of 4

Thread: How do I add records to an existing text file?

  1. #1
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    795

    Default How do I add records to an existing text file?

    If the file already exists, I need to append records to a plain text file, but cannot work out how to do it. :o

    so far, but what do I need to add:

    Code:
    IF File.exists("xxx.txt") then
        fp = File.open("xxx.txt",FILE_RW_SHARED)
    ... get to the end of the file ready to add records
    ELSE
        fp = File.create("xxx.txt")
    end if
    ...  continue script
    
    fp.write_line("blaa,blaa,blaa")
    fp.flush()
    fp.close()
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

  2. #2
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,701

    Default Re: How do I add records to an existing text file?

    Your code can be replaced with a single line of Xbasic:
    Code:
    save_to_file("xxx.txt","blaa,blaa,blaa",.t.)

    Lenny Forziati
    Vice President, Internet Products and Technical Services
    Alpha Software Corporation

  3. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: How do I add records to an existing text file?

    Quote Originally Posted by Lenny Forziati View Post
    Your code can be replaced with a single line of Xbasic:
    Code:
    save_to_file("xxx.txt","blaa,blaa,blaa",.t.)
    But sometimes it is helpful to know how to do it the hard way.

    Code:
    IF File.exists("xxx.txt") then
        fp = File.open("xxx.txt",FILE_RW_SHARED)
        bts = fp.bytes_get()
        fp.seek(bts)
    ELSE
        fp = File.create("xxx.txt",FILE_RW_EXCLUSIVE) 'not optional, I think
    end if
    ...  continue script
    
    fp.write_line("blaa,blaa,blaa")
    fp.flush()
    fp.close()

  4. #4
    Member Graham Wickens's Avatar
    Real Name
    Graham Wickens
    Join Date
    Apr 2000
    Location
    Gloucestershire, UK
    Posts
    795

    Default Re: How do I add records to an existing text file?

    Thanks Gentlemen.
    --
    Support your local Search and Rescue Unit, Get Lost!

    www.westrowops.co.uk

Similar Threads

  1. Add text to existing field
    By Adam Carbery in forum Alpha Five Version 6
    Replies: 3
    Last Post: 09-14-2005, 03:54 PM
  2. Add tag to exported text file
    By dparkins in forum Alpha Five Version 5
    Replies: 2
    Last Post: 02-18-2005, 10:00 AM
  3. Report existing and non-existing records
    By Kevin Gillan in forum Alpha Five Version 6
    Replies: 3
    Last Post: 02-14-2005, 08:15 AM
  4. Import data from Text File to existing DBF
    By Don Patterson in forum Alpha Five Versions 2 and 3
    Replies: 1
    Last Post: 02-07-2002, 05:41 PM
  5. Add to Existing Code
    By forskare in forum Alpha Five Version 4
    Replies: 7
    Last Post: 01-11-2002, 01:04 PM

Bookmarks

Posting Permissions

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