英文:
How can I delete a file that is currently in use by another process in cpp win32?
问题
在卸载我的msi应用程序时,调用DeleteFile()函数后,Program Data文件夹中的日志文件(.txt)未被删除。通过使用GetErrorCode(),我可以检查它返回错误代码32,这意味着文件正在使用中。有没有办法在卸载时删除这些日志文件?理论或源代码 - 任何形式的帮助将不胜感激。
我尝试使用下面的代码,但没有成功。甚至fclose()操作也没有产生任何积极的结果。
SHFILEOPSTRUCT file_op = {
NULL,
FO_DELETE,
dir,
"",
FOF_NOCONFIRMATION |
FOF_NOERRORUI |
FOF_SILENT,
false,
0,
"" };
SHFileOperation(&file_op);
英文:
While uninstalling my msi application , the log files(.txt) in Program Data folder are not getting deleted after calling DeleteFile() function. By using GetErrorCode() I could check its returning error code 32 which implies the file is in use.Is there a way I can delete these log files while uninstallation? Theory or source -Any kind of help would be appreciated.
I tried using the below code but it didn't work. Even fclose() operation didn't yield any positive results.
SHFILEOPSTRUCT file_op = {
NULL,
FO_DELETE,
dir,
"",
FOF_NOCONFIRMATION |
FOF_NOERRORUI |
FOF_SILENT,
false,
0,
"" };
SHFileOperation(&file_op);
答案1
得分: 0
你无法删除正在被另一个进程使用的文件。您可以尝试使用MoveFileEx
并带有MOVEFILE_DELAY_UNTIL_REBOOT
标志。
有关更多详细信息,建议您参考以下线程:
https://stackoverflow.com/questions/215461/how-can-i-force-the-deletion-of-locked-files-in-c-c#215466
英文:
You couldn't delete a file that is currently in use by another process. You could try to use Use MoveFileEx
with the MOVEFILE_DELAY_UNTIL_REBOOT flag
.
For more details I suggest you could refer to the threads:
https://stackoverflow.com/questions/215461/how-can-i-force-the-deletion-of-locked-files-in-c-c#215466
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论