在目录中查找最后创建的 FILE,C++
Finding the last created FILE in the directory, C++
虽然我在互联网上搜索过,但没有像我这样的问题。我的问题是,我想获取在目录中创建的最后一个文件的名称。我的系统将在这段代码的目录中创建来自我的相机的 /.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;
}
我没有使用额外的库我使用了下面的库,因为它可以在 link 中看到:
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;
}
虽然我在互联网上搜索过,但没有像我这样的问题。我的问题是,我想获取在目录中创建的最后一个文件的名称。我的系统将在这段代码的目录中创建来自我的相机的 /.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;
}
我没有使用额外的库我使用了下面的库,因为它可以在 link 中看到:
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;
}