我在开发的传真服务器软件上遇到了几乎相同的问题。我必须按照从成千上万的收到的顺序发送传真(全部存储在目录中)。我采取的解决方案(这是缓慢的开始,但运行速度快)是使用
SearchRec.Time
为重点,以使所有文件的排序列表。该文件是在列表中后,我设置文件属性为faSysFile:
NewAttributes := Attributes or faSysFile;
现在,当我做了新的搜索与
FileAttrs := (faAnyFile and not faDirectory);
唯一不属于文件faSysFile会显示出来,所以我可以在列表中添加新的文件。 现在你有一个列表,所有的文件按时间排序。 不要忘记,当您启动应用程序时,第一步是从文件夹中的文件中移除faSysFile属性,以便可以再次处理它们。
procedure FileSetSysAttr(AFileName: string);
var
Attributes, NewAttributes: Word;
begin
Attributes := FileGetAttr(AFileName);
NewAttributes := Attributes or faSysFile;
FileSetAttr(AFileName, NewAttributes);
end;
procedure FileUnSetSysAttr(AFileName: string);
var
Attributes, NewAttributes: Word;
begin
Attributes := FileGetAttr(AFileName);
NewAttributes := Attributes and not faSysFile;
FileSetAttr(AFileName, NewAttributes);
end;
procedure PathUnSetSysAttr(APathName: string);
var
sr: TSearchRec;
FileAttrs: Integer;
begin
FileAttrs := (faAnyFile and not faDirectory) and (faAnyFile or faSysFile);
APathName := IncludeTrailingBackslash(APathName);
if SysUtils.FindFirst(APathName + '*.*', FileAttrs, sr) = 0 then
try
repeat
if (sr.Attr and faDirectory) = 0 then
FileUnSetSysAttr(APathName + sr.Name);
until SysUtils.FindNext(sr) <> 0;
finally
SysUtils.FindClose(sr);
end;
end;
我知道这不是最好的解决方案,但适用于我。
你可以添加一些东西到过程中,以便找到文件不涉及迭代磁盘上的文件?另外,你是在机器上运行程序还是通过网络运行?如果是后者,我建议你尝试在机器上运行程序,这样文件夹迭代不会在网络上运行。 –
我不知道如何将它变成答案,但是如果您可以在远程计算机上安装软件,我想知道是否可以使用Power Shell版本2中的远程功能。可以在远程计算机上运行Power Shell脚本以查找最旧的文件,并且您将在本地获取文件信息。我不确定你会如何得到答案,但我相信这是可能的。 –