文件删除XP下的问题 [英] File Delete problems under XP

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

问题描述

我在XP和Windows 7下删除文件时遇到问题



unlink和DeleteFile在Window 7下失败,但访问被拒绝,但Win32DeleteFile()有效。在XP下,Win32DeleteFile()失败。



文件未被使用,并且没有显示进程资源管理器,并且可以使用资源管理器一直没有问题地删除。它可能有一个文件句柄打开,但不是独占的,因为资源管理器可以删除该文件,我只是不能在应用程序中。



任何想法?



谢谢!

I am having trouble deleting files under XP and Windows 7

unlink and DeleteFile fail under Window 7 with access denied, but Win32DeleteFile() works. Under XP, Win32DeleteFile() fails.

The file is not in use, and does not show up process explorer, and can be deleted always without problems using explorer. It probably has a file handle open, but not exclusive, etc as explorer can delete the file, I just can''t in the application.

Any ideas?

Thanks!

推荐答案

嗨大卫,



实际上使用此API有一些限制。这些限制与操作系统和删除文件的位置有关。



请参阅下面分享的MSDN链接的要求部分,

http:// msdn。 microsoft.com/en-us/library/windows/desktop/bb762265(v=vs.85).aspx [ ^ ]



And如果你的操作系统仍然满足这些要求,那么请分享你试图删除文件的代码。



仅供参考:Windows 7不支持此API。 br />


再见。
Hi David,

Actually there is some restrictions in using this API. And these restriction are related to OS and the location from which you are deleting the files.

Please refer to the "Requirements" sections of the MSDN link shared below,
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762265(v=vs.85).aspx[^]

And if your OS still satisfy those requirement then do share your piece of code that is trying to delete the file.

FYI: this API is not supported in Windows 7.

Bye.


我发现Win32DeleteFile()在Win 7下工作,unlink / DeleteFile在XP下工作,所以我使用的是其中一种。



谢谢!
What I have discovered is that Win32DeleteFile() works under Win 7, and unlink/DeleteFile works under XP, so I am using one or the other depending.

Thanks!


您可以尝试的另一种策略是将有问题的文件发送到回收站。以下是我的一些代码的变体(重新输入;如果存在编译错误则道歉):



Another strategy you can try is to send the file(s) in question to the recycling bin. Here is a variation on some of my code (retyped; apologies if there is a compile error):

bool FileToRecycleBin(const char* szFileIn)
{
  char  szFile[1030];
  SHFILEOPSTRUCT  op = {0};

  strcpy_s(szFile, szFileIn);
  szFile[strlen(szFile)+1] = '\0'; // Extra terminating NUL required...

  op.wFunc = FO_DELETE;
  op.pFrom = szFile;
  op.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;

  return 0 == SHFileOperation(&op);
}


这篇关于文件删除XP下的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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