gpt4 book ai didi

c++ - 在目录中查找最后创建的 FILE,C++

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:09:21 24 4
gpt4 key购买 nike

即使我在互联网上搜索也没有像我这样的问题。我的问题是,我想获取在目录中创建的最后一个文件的名称。我的系统将在这段代码的目录中创建来 self 的相机的/.png 文件,我希望我的代码采用上次创建的代码。我想用这段代码来做,

string processName()
{
// FILETIME Date = { 0, 0 };
// FILETIME curDate;
long long int curDate = 0x0000000000000000;
long long int date = 0x0000000000000000;
//CONST FILETIME date={0,0};
//CONST FILETIME curDate={0,0};
string name;
CFileFind finder;
FILETIME* ft;

BOOL bWorking = finder.FindFile("*.png");
while (bWorking)
{

bWorking = finder.FindNextFile();

date = finder.GetCreationTime(ft) ;

//ftd.dwLowDateTime = (DWORD) (date & 0xFFFFFFFF );
//ftd.dwHighDateTime = (DWORD) (date >> 32 );


if ( CompareFileTime(date, curDate))
{
curDate = date;
name = (LPCTSTR) finder.GetFileName();
}



}
return name;
}

我没有使用额外的库,我使用了以下库,因为它可以在链接中看到:

https://msdn.microsoft.com/en-US/library/67y3z33c(v=vs.80).aspx

在这段代码中,我尝试为 64 位 FILETIME 变量赋予初始值,并将它们与这个 while 循环进行比较。但是我收到以下错误。

1   IntelliSense: argument of type "long long" is incompatible with parameter of type "const FILETIME *"        44  25  
2 IntelliSense: argument of type "long long" is incompatible with parameter of type "const FILETIME *" 44 31

getCreationTime方法一个参数为

参数:pTimeStamp:指向包含文件创建时间的 FILETIME 结构的指针。

refTime:对 CTime 对象的引用。

最佳答案

我想我修正了你的代码。必须更改某些类型等:

string processName()
{
FILETIME bestDate = { 0, 0 };
FILETIME curDate;
string name;
CFileFind finder;

finder.FindFile("*.png");
while (finder.FindNextFile())
{
finder.GetCreationTime(&curDate);

if (CompareFileTime(&curDate, &bestDate) > 0)
{
bestDate = curDate;
name = finder.GetFileName().GetString();
}
}
return name;
}

关于c++ - 在目录中查找最后创建的 FILE,C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29880039/

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