问题
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
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 method take one parameter as
Parameters: pTimeStamp: A pointer to a FILETIME structure containing the time the file was created.
refTime: A reference to a CTime object.
回答1:
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;
}
来源:https://stackoverflow.com/questions/29880039/finding-the-last-created-file-in-the-directory-c