[erlang-questions] size of an open file

jm <>
Wed May 14 10:15:57 CEST 2008



Bengt Kleberg wrote:
> Greetings,
>
> You have 2 possibilities according to the manual of the file module:
> 1) file:position/2 should return the file size, if called with 'eof' as
> Position
> 2) if this is for debugging you can use file:pid2name/1 and get the file
> name (for subsequent use in file:read_file_info/1).
>
>   

Thanks. Last question I hope. In attempting to tail a log file:  How do 
you detect that the file has rolled over, ie a new log file has been 
created?
Is there a smarter way than comparing the size of the open file and the 
size of the file by name? I can see a couple of problems with this method.
To begin with if the new log file grows larger than the old log file 
before there is a chance to switch files. I suppose you could do

 SizeOfOpen =:= SizeofNamedFile

but this doesn't seem right. Really, a comparison should be done on the 
filenames, ie compare the name of the currently open file with that of 
the requested filename to detect a roll over, but I don't see a 
file:read_file_info/1 for open files.

Jeff.




More information about the erlang-questions mailing list