- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我观察到,如果要删除的文件夹中文件很少且该文件夹已打开(在 Total Commander 中),则在调用 TDirectory.Delete(x) 后立即调用 DirectoryExists(x) 返回 true。
换句话说:
begin
TDirectory.Delete('x', true); <-- 'Delete' exited but the folder is still not fully deleted
if SysUtils.DirectoryExists('x')... <-- This returns true
end;
这是正常行为吗?
“解决方案”是这样的:
begin
TDirectory.Delete('x', true);
Sleep(1000); //wait for Delete to finish
if SysUtils.DirectoryExists('x')...
end;
问题:我如何知道删除何时准备就绪(如何消除 sleep )?
注意: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.
所以可能另一个进程也有该目录的句柄(病毒扫描程序?)。
如果您需要清空该目录,请将其清空,而不是删除它并在之后重新创建它。最终你总是要为肮脏的黑客行为付出代价;)
关于delphi - TDirectory.Delete 似乎是异步的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42809389/
我观察到,如果要删除的文件夹中文件很少且该文件夹已打开(在 Total Commander 中),则在调用 TDirectory.Delete(x) 后立即调用 DirectoryExists(x)
TDirectory.GetFiles 有一个名为 SearchPattern 的参数。 Embarcadero 的文档显示 The mask used when matching file name
GetParent('c:\1\2\') 的结果是 'c:\1\2'。 GetParent('c:\1\2') 的结果是 'c:\1'。 这是正常/预期的行为吗?如果是,其背后的逻辑是什么? 最佳答案
当“Folder”长度为 259 个字符时,IOUtils.TDirectory.GetDirectoryRoot(Folder) 会出现错误(是的,它在末尾包含\分隔符): Project Test
我是一名优秀的程序员,十分优秀!