gpt4 book ai didi

Delphi - 从给定路径获取最后创建的文件夹名称

转载 作者:行者123 更新时间:2023-12-03 15:54:07 25 4
gpt4 key购买 nike

是否有函数可以从给定路径获取最后创建的文件夹?我想查看最后创建的文件夹,以检查我的相机今天是否拍摄了照片。我想到的另一种方法是获取系统日期,然后开始搜索包含当前日期的文件夹。但是,如果相机日期错误,那么这种方法将不起作用!谢谢。还有其他想法吗?

例如:

if lastcreatedfolder(dir_path):='05012016' then 
showmessage('TODAY A FOLDER WAS CREATED')
else
showmessage('NO FOLDER WAS CREATED TODAY!');

最佳答案

Delphi 2010 还具有 IOUtils.pas 单元。

使用 native ,可以找到最后创建的文件夹,如下所示:

uses
IOUtils, Types, DateUtils;

function FindLastCreatedDirectory(const APath: string): string;
var
LastCreateTime : TDateTime;
PathsInQuestion: TStringDynArray;
n : Integer;
begin
LastCreateTime := MinDateTime;
Result := '';

PathsInQuestion := TDirectory.GetDirectories(APath);
for n := Low(PathsInQuestion) to High(PathsInQuestion) do
begin
if CompareDateTime(TDirectory.GetCreationTime(PathsInQuestion[n]), LastCreateTime) = GreaterThanValue then
begin
LastCreateTime := TDirectory.GetCreationTime(PathsInQuestion[n]);
Result := PathsInQuestion[n];
end;
end;
end;

关于Delphi - 从给定路径获取最后创建的文件夹名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34613626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com