Delete record in ASCII file, I really can't figure it out

Delete record in ASCII file, I really can't figure it out

Post by Remco Groot Beume » Thu, 12 Sep 2002 00:27:49



Hello,

I have a urgent problem with a little program I wrote. The program must read
records from a comma seperated textfile (ascii) and transfer them to a
database.
The textfile is also used by a scanprogram, which writes the records to the
textfiles. The textfile is shared and only a recordlock is placed, when the
scanprogram writes records to the file.
Now I need to read a record (which works with my current textdriver) and
delete the record in the textfile. But how can I delete a record in a
textfile (1 row). I tried al kind of things but nothing seems to work.

Has anyone got any suggestions where to look, it would be very appreciated.

Thanxs,

Remco Groot Beumer

 
 
 

Delete record in ASCII file, I really can't figure it out

Post by David Marflee » Sat, 14 Sep 2002 05:05:45


I don't think there is any easy way to do this.  If the records are of
variable length, the only obvious solution would be to read the contents of
the file into a string buffer, omitting the record marked for deletion.
Then open the file again in binary access mode and paste the contents of the
buffer into the file using the Put statement.  Pretty crude I know, but this
is low-level I/O we are talking about.

Regards

Paul



Quote:> Hello,

> I have a urgent problem with a little program I wrote. The program must
read
> records from a comma seperated textfile (ascii) and transfer them to a
> database.
> The textfile is also used by a scanprogram, which writes the records to
the
> textfiles. The textfile is shared and only a recordlock is placed, when
the
> scanprogram writes records to the file.
> Now I need to read a record (which works with my current textdriver) and
> delete the record in the textfile. But how can I delete a record in a
> textfile (1 row). I tried al kind of things but nothing seems to work.

> Has anyone got any suggestions where to look, it would be very
appreciated.

> Thanxs,

> Remco Groot Beumer


 
 
 

Delete record in ASCII file, I really can't figure it out

Post by the other g » Sun, 15 Sep 2002 23:09:09


On Thu, 12 Sep 2002 20:05:45 +0000 (UTC), "David Marfleet"


>I don't think there is any easy way to do this.  If the records are of
>variable length, the only obvious solution would be to read the contents of
>the file into a string buffer, omitting the record marked for deletion.
>Then open the file again in binary access mode and paste the contents of the
>buffer into the file using the Put statement.  Pretty crude I know, but this
>is low-level I/O we are talking about.

>Regards

>Paul

To really read variable length record file safely, use the SEQUENTIAL
Read function. It loads a line taking the vbCRLF as a record
delimiter.

Called SEQUENTIAL because to get one record, you have to go back to
the offset 0 (position 1) then re-read everything. Don't you love
variable lenght records? Actually, it's quite fast.

Comma Separated Values files are parsed that way.



>> Hello,

>> I have a urgent problem with a little program I wrote. The program must
>read
>> records from a comma seperated textfile (ascii) and transfer them to a
>> database.
>> The textfile is also used by a scanprogram, which writes the records to
>the
>> textfiles. The textfile is shared and only a recordlock is placed, when
>the
>> scanprogram writes records to the file.
>> Now I need to read a record (which works with my current textdriver) and
>> delete the record in the textfile. But how can I delete a record in a
>> textfile (1 row). I tried al kind of things but nothing seems to work.

>> Has anyone got any suggestions where to look, it would be very
>appreciated.

>> Thanxs,

>> Remco Groot Beumer

 
 
 

1. Q: CRecordSet::Delete() doesn't really delete??

hi,

I'm writing a program that keeps the states of the program in a table of a
access/odbc database, these states change quite rapidly and when I update
the database I delete the records and write new ones. Because access sets
the deleted records to NULL (but doesn't really delete them) the old records
still take up space in the database, this means that my database grows to
*really* delete the records?

I've read about the CompactDatabase() function, but this creates a new
database and that's not want I want (I then loose my odbc connection...)

thx,

Ed

2. Universal Server - Any sites ?

3. DELETE FILE doesn't delete the file

4. Loading Oracle load-file into Informix

5. Deleting device doesn't delete DAT file

6. free online classes for Analysis Services?

7. delete offline DB doesn't delete files?

8. Data source name not found and no default driver specified

9. Backup: delete old files / Msdb.backupset records delete

10. Deleted records when text file is linked as table (#deleted)

11. if you will promise Allahdad's swamp against cans, it will angrily depart the unit

12. Q: delete in ASCII file???

13. Delete all 'not found' records