有没有办法删除FILE_FLAG_DELETE_ON_CLOSE? [英] is there a way to remove FILE_FLAG_DELETE_ON_CLOSE?

查看:133
本文介绍了有没有办法删除FILE_FLAG_DELETE_ON_CLOSE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想用FILE_FLAG_DELETE_ON_CLOSE打开一个临时文件。但是有些情况下,需要保留临时文件,并且相当大

我想在打开的句柄上删除FILE_FLAG_DELETE_ON_CLOSE属性?这可能吗?复制文件或重命名的内容是不是我想要的,我想删除属性。这是由于我如何处理一些写入,在我的应用程序关闭句柄将打开我的竞争条件

解决方案

你可以反过来做。
首先打开文件,指定 FILE_SHARE_DELETE
然后,当你需要关闭文件时,用 FILE_DELETE_ON_CLOSE 再次打开它,然后关闭这两个句柄。或者,关闭它,它不会被删除。


in my app I'd like to open a temp file with FILE_FLAG_DELETE_ON_CLOSE. however there are some cases where the temp file needs to be kept and is quite large

I'd like to remove the FILE_FLAG_DELETE_ON_CLOSE attribute on an opened handle? is this possible? copying the contents of the file or renaming isnt quite what I want, I'd like to remove the attribute. this is due to how i'm transacting some writes, in my app closing the handle will open me up to a race condition

解决方案

You could do it the other way around. Open the file first, specifying FILE_SHARE_DELETE. Then, when you need to close the file, open it again with FILE_DELETE_ON_CLOSE, then close both handles. Or, just close it, and it won't be deleted.

这篇关于有没有办法删除FILE_FLAG_DELETE_ON_CLOSE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆