TDirectory.Delete 好像是异步的
TDirectory.Delete seems to be asynchronous
我观察到在调用 TDirectory.Delete(x) returns 后立即调用 DirectoryExists(x) 如果要删除的文件夹中的文件很少并且文件夹处于打开状态(总计指挥官).
换句话说:
begin
TDirectory.Delete('x', true); <-- 'Delete' exited but the folder is still not fully deleted
if SysUtils.DirectoryExists('x')... <-- This returns true
end;
这是正常行为吗?
"solution"是这样的:
begin
TDirectory.Delete('x', true);
Sleep(1000); //wait for Delete to finish
if SysUtils.DirectoryExists('x')...
end;
问题:如何知道删除准备就绪(如何消除休眠)?
注意:Total Commander 不会阻止删除文件夹(我猜),因为文件夹无论如何都会被删除(一段时间后)。
查看有关 RemoveDirectory 的 msdn 页面:https://msdn.microsoft.com/en-us/library/windows/desktop/aa365488(v=vs.85).aspx
备注部分说:
The RemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed.
所以可能另一个进程也有该目录的句柄(病毒扫描程序?)。
如果您需要清空该目录,请将其清空,而不是将其删除并在之后重新创建。最后你总是为肮脏的黑客付出代价;)
我观察到在调用 TDirectory.Delete(x) returns 后立即调用 DirectoryExists(x) 如果要删除的文件夹中的文件很少并且文件夹处于打开状态(总计指挥官).
换句话说:
begin
TDirectory.Delete('x', true); <-- 'Delete' exited but the folder is still not fully deleted
if SysUtils.DirectoryExists('x')... <-- This returns true
end;
这是正常行为吗?
"solution"是这样的:
begin
TDirectory.Delete('x', true);
Sleep(1000); //wait for Delete to finish
if SysUtils.DirectoryExists('x')...
end;
问题:如何知道删除准备就绪(如何消除休眠)?
注意:Total Commander 不会阻止删除文件夹(我猜),因为文件夹无论如何都会被删除(一段时间后)。
查看有关 RemoveDirectory 的 msdn 页面:https://msdn.microsoft.com/en-us/library/windows/desktop/aa365488(v=vs.85).aspx
备注部分说:
The RemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed.
所以可能另一个进程也有该目录的句柄(病毒扫描程序?)。
如果您需要清空该目录,请将其清空,而不是将其删除并在之后重新创建。最后你总是为肮脏的黑客付出代价;)