c - When terminating a process is it possible to delete a file? -
i need write windows c application creates file, , file needs deleted when application terminated(both in case of graceful termination or forced kill).
one more requirement user should able open file in read-only mode(may using notepad). read in java(i.e documentbuilder::parse)
i have written following code
handle hfile = createfile("d:\\test.xml", generic_write, file_share_read, null, create_always, file_flag_delete_on_close, null);
when open file(i.e test.xml) in notepad.exe, error saying "the process cannot access file because being used process".
however, following code works fine
handle hfile = createfile("d:\\test.xml", generic_write, file_share_read, null, create_always, file_attribute_normal, null);
but problem is, not delete file(i.e when application killed).
any appreciated.
in case suggest approach works both on windows , unix, great(e.g. using boost libraries).
the documentation says:
the file deleted after of handles closed, includes specified handle , other open or duplicated handles.
if there existing open handles file, call fails unless opened file_share_delete share mode.
subsequent open requests file fail, unless file_share_delete share mode specified.
so, need arrange file_share_delete
passed process opens file.
Comments
Post a Comment