Testing file deletion from under ostream object.

J

James Vanns

How would one go about testing for the deletion of a file that sits
under an o[f]stream object? I've tried is_open, good(), fail(), eof(),
bad() and catching exceptions - nothing! Aparently the << operator
still succeeds which I guess is because it's still writing to the
buffer (but even flush() doesn't fail). If an external program (such as
rm or del) deletes the physical file - how can I catch this in the
program? In a relatively elegant, non-hacky way!?

Regards,

Jim Vanns
 
V

Victor Bazarov

James said:
[...] If an external program (such
as rm or del) deletes the physical file - how can I catch this in the
program? In a relatively elegant, non-hacky way!?

There are no means for that in the language. C++ assumes a _single_thread_
_single_process_ execution environment for its definitions. Whatever your
OS allows you to do and the consequence of that is defined at the OS level.
Inter-process communication (and recognizing the deletion of an external
storage unit falls under that) should be asked about in a newsgroup for
your platform. See the FAQ for suggestions on that.

V
 
R

Rolf Magnus

James said:
How would one go about testing for the deletion of a file that sits
under an o[f]stream object?

There is no standard way to do that. On some operating systems, that can't
even happen, because files are not deleted as long as there are still some
references to them (including open file streams).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top