Reading file contents when file has changed

OlaOst olaa81 at gmail.com
Fri Jul 13 13:35:36 PDT 2012


I'm working on a program (using dmd 2.059 under windows) that 
automatically reloads the contents of a file if it has changed, 
by checking the last modified timestamp on the file every 0.2 
seconds, then using the readText function in std.file to read in 
the file contents.

It works pretty well, but every once in a while I get a "The 
process cannot access the file because it is in use by another 
process" error message. I guess this happens when my D program 
tries to read the file before the text editor manages to close 
its handle on the file.

This would be fair enough if I was writing to the file in my D 
program, but I only want to read from it. Is this a bug or is 
there a better way to get file contents in D?


More information about the Digitalmars-d-learn mailing list