Need to lock read a text file, then delete...

  • Thread starter Thread starter Alessandro
  • Start date Start date
A

Alessandro

Hi everybody,
I tried to find some information about my subject with google, but I
didn't find anything.

I need to read a text file, process the entire content, then kill. In
the meantime I have to be sure that no one could write on it. So I
opened with read write lock, but when i closed it, before deleting,
someone wrote something, and I lost the information because immediately
after I killed it.

Have you any suggestion?

Sorry for my bad english.

Thanks in advance,
Alessandro Noro
 
Alessandro said:
Hi everybody,
I tried to find some information about my subject with google, but I
didn't find anything.

I need to read a text file, process the entire content, then kill. In
the meantime I have to be sure that no one could write on it. So I
opened with read write lock, but when i closed it, before deleting,
someone wrote something, and I lost the information because immediately
after I killed it.

Have you any suggestion?

Rename the file before you start reading it. That way, any writer will
(presumably) find the file missing, and create a new blank one to write
to.

I guess we are talking about parsing a log file or something like that?
Sorry for my bad english.

Better than my Italian.
 
Thanks Larry for your quick reply.

I thought about the solution You suggest me, but unfortunately I cannot
do so, because I could delete the Input file only if I could find other
files (depending on what I find inside the Input file). Otherwhise I
have to wait, and leave the Input file "free" for more writings.
I also thought about reading the Input file, then remove all the lines
inside, leaving it empty. But I don't know how to do this...

Thanks again.
Alessandro Noro
 
Copy the file to another location.
Delete the file
Create the new file for new additions
Do the processing of the file in your code at the new location.
Delete file at new location so you can do the same next time.
 
Allessandro

This is an old Jewish witz

Bram asks to the Rabi: "Rabi can God make everything he wants?
The Rabi answers: "Yes of course Bram"
Bram asks: "Rabi can God make a stone which he cannot lift himself?

Your question sounds the same for me.
(I never forget this witz because there is so much true in it).

Cor
 
Back
Top