在win XP上无法删除文件夹 [英] Cannot delete folder on win XP
本文介绍了在win XP上无法删除文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi all,
I have small app (was written by Delphi 7) to delete a folder (include sub folder and children files).
Main code of this app is below method:
procedure TForm1.DeleteDirectory(const Name: string);
var
F: TSearchRec;
begin
//Delete image folder
if FindFirst(Name + '\*', faAnyFile, F) = 0 then begin
try
repeat
if (F.Attr and faDirectory <> 0) then begin
if (F.Name <> '.') and (F.Name <> '..') then begin
DeleteDirectory(Name + '\' + F.Name);
end;
end else begin
DeleteFile(Name + '\' + F.Name);
end;
until FindNext(F) <> 0;
RemoveDir(Name);
finally
FindClose(F);
end;
end;
end;
Problem:
When I run app in Window 7, selected folder (folder name is input param of method) was deleted (all children files, sub folder and main folder were deleted).
However, if i run app in window XP, all children files were deleted but folders (sub folder and main folder cannot be deleted).
I have solution for this problem, but i want to know why, why program can delete folders on window 7 but cannot delete folders on window XP?
Thanks for your support!
我的尝试:
我有解决方案,我想知道问题的原因
What I have tried:
I have solution, i want know cause of problem
推荐答案
似乎用Windows XP进行文件搜索函数(Windows API函数FindFirstFile,FindFirstFileEx)将锁定目录。
因此,搜索句柄未被删除时,搜索的目录无法删除关闭(就像实际打开的文件一样无法删除)。
似乎这个行为已经被更新的Windows版本更改了。
我今天的google-fu似乎不是很强大,但我发现至少有一次讨论也是如此( Google网上论坛 [ ^ ] ):
It seems that with Windows XP the file search functions (Windows API functions FindFirstFile, FindFirstFileEx) will lock the directory.
As a result the directory which is searched can't be deleted while the search handle has not been closed (like a file that is actually opened can't be deleted).
It seems also that this behaviour has been changed with newer Windows versions.
My google-fu seems to be not very strong today but I found at least one discussion where this has been observed too (Google Groups[^]):
引用:
..似乎在XP上,FindFirstFile会锁定目录,而在
上
Win7它没有。
..seems that on XP, FindFirstFile locks the directory, while on
Win7 it does not.
这篇关于在win XP上无法删除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文