1.获取文件夹创建时间
SYSTEMTIME GetFolderCreateTime(CString sFolder)
{
SYSTEMTIME screatetime;
HANDLE hDir;
hDir = CreateFile(sFolder,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_DELETE,NULL,
OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL);//打开现存目录 只读方式打开即可
FILETIME lpCreateTime,lpAccessTime,lpWriteTime;
if(GetFileTime(hDir,&lpCreateTime,&lpAccessTime,&lpWriteTime))
{
FILETIME fcreatetime;
FileTimeToLocalFileTime(&lpCreateTime,&fcreatetime);//转换为本地时间
FileTimeToSystemTime(&fcreatetime,&screatetime);//转换为系统时间
}
CloseHandle(hDir);//关闭文件句柄
return screatetime;
}
2.获取文件夹内文件名
void GetFolderFile(CString sFolder, CStringArray &fileList)
{
fileList.RemoveAll();
CString strMatch;
if(sFolder.Right(1) == "\\")
strMatch = sFolder + "*.*";
else
strMatch = sFolder + "\\*.*";
CString strFullName;
CFileFind finder;
BOOL bWorking = finder.FindFile(strMatch);
while (bWorking)
{
bWorking = finder.FindNextFile();
if(finder.IsDots())
continue;
if(finder.IsDirectory())
{
continue; //跳过子文件夹
}else
{
strFullName = finder.GetFilePath();
fileList.Add(strFullName);
}
}
finder.Close();
}
3.获取文件最后修改日期
bool GetFileModifyDate(CString filePathName, SYSTEMTIME &modDate)
{
HANDLE hFile;
WIN32_FIND_DATA wfd;
SYSTEMTIME systime;
FILETIME localtime;
memset(&wfd, 0, sizeof(wfd));
if((hFile=FindFirstFile(filePathName, &wfd))==INVALID_HANDLE_VALUE)
return false;
//转换时间
FileTimeToLocalFileTime(&wfd.ftLastWriteTime,&localtime);
FileTimeToSystemTime(&localtime,&systime);
modDate = systime;
return true;
}