问题描述
即使我搜索了互联网,也没有像我这样的问题.我的问题是,我想获取目录中创建的最后一个文件的名称.我的系统将在此代码的目录中创建来自我的相机的/.png文件,我希望我的代码采用最近创建的文件.我想用这段代码来做
Even though I searched there isn't any problem like mine in the internet. my problem is, I want to get the name of the last file created in the directory. My system will create /.png files coming from my Camera in the directory of this code and I want my code to the take last created one. I want do it with this code,
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;
}
我没有使用额外的库,因此我在链接中使用了以下库:
I didnt use extra libraries I used the following one as it can be seen in the link :
https://msdn.microsoft.com/en-US/library/67y3z33c(v=vs.80).aspx
在这段代码中,我尝试将初始值赋予64位FILETIME变量,并将其与while循环进行比较.但是我得到以下错误.
In this code I tried to give initial values to 64 bit FILETIME variables, and compare them with this while loop. However I get the following errors.
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方法采用一个参数作为
getCreationTime method take one parameter as
参数:pTimeStamp:指向包含文件创建时间的FILETIME结构的指针.
Parameters:pTimeStamp: A pointer to a FILETIME structure containing the time the file was created.
refTime:对CTime对象的引用.
refTime: A reference to a CTime object.
推荐答案
我想我已经修复了您的代码.必须更改某些类型,例如:
I think I fixed your code. Had to change some types etc:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!