如何在C ++中获取文件时间
我在获取文件时间时遇到问题..有谁知道如何获取文件时间?
我有一个代码获取某个目录的文件名我的问题是我不知道如何将文件时间放在目录中的每个文件上...
这是我的代码:
#include <vector>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <systypes.h>
#include <sysstat.h>
#include <time.h>
#include <exception>
#include <WinBase.h>
using namespace std;
int ifException(string directory) throw()
{
DWORD returnvalue;
returnvalue = GetFileAttributes(directory.c_str());
if(returnvalue == ((DWORD)-1))
{
return 0;
}
else
{
return 1;
}
}
vector <string> GetPath(string path)
{
char directory[9999];
vector <string> filelist;
string buffer;
strcpy_s(directory,path.c_str());
BOOL checker;
try
{
ifException(directory);
}catch(int i)
{
if (i==0)
{
_getch();
exit(1);
}
}
buffer = findFileData.cFileName;
filelist.push_back(buffer);
checker = FindNextFile(hFind, &findFileData);
while(checker)
{
if(checker == 0)
{
filelist.resize(filelist.size());
return filelist;
}
checker = FindNextFile(hFind, &findFileData);
buffer = findFileData.cFileName;
filelist.push_back(buffer);;//save file list in vector
}
return filelist;
}
int main()
{
string path;
path="C:\Documents and Settings\OJT\My Documents\game\FSNPC\*.*";// the directory
vector <string> handler;
handler = GetPath(path);
for (unsigned i=1;i<handler.size()-1;i++)
{
cout << handler[i]<<endl;//print out the vector
}
_getch();
}
没有找到相关结果
已邀请:
5 个回复
壬驴拿歪竞
功能,查找它,我有一段时间没见过Windows。 更新:看这里和这里
挂帘妈乡
杭难插
购藏盗码韦
函数,它允许您检索任何文件或目录的创建,上次访问或上次修改日期和时间。它通过用时间值填充指定为参数的
结构来完成此操作。
由于你关心的只是创建时间,你可以忽略最后两个参数。它们是可选的。您可以在MSDN上找到检索文件上次写入时间的完整示例。 一旦使用适当的值填充
结构,您可能希望使用
函数将该值转换为适合显示的格式。
癸痊醒
有效地仅返回相对于1601年1月1日的64位时间戳,
将其转换为具有小时,分钟,日,月等字段的结构...)。