Hi,
I want to retreive the file create / modify date for a bunch of text files.
Anyone know any C/C++ code to acheive this?
Printable View
Hi,
I want to retreive the file create / modify date for a bunch of text files.
Anyone know any C/C++ code to acheive this?
If using Windows, look up the GetFileTime() function, otherwise look up the stat() function.
If its related directly to windows programming
then this could make your life easier :
If you have any questions fee lfree to pm me, i put this togetherCode:#include <windows.h>
using namespace std;
int main()
{
HANDLE hFind;
WIN32_FIND_DATA FindData;
char line1[255] = "SomeDirectory\\Somefile.someextention";
/*
after specifying you directory, to do all the text files in the dir
use the file name *.txt, to do all the files use *.*
Ex. "c:\\windows\\*.exe" will read all of the exe files
in the windows folder.
Ex. "c:\\windows\\*.*" will read every file in the windows
directory.
*/
hFind = FindFirstFile(line1, &FindData); //Find first file
while (FindNextFile(hFind, &FindData)) //Find Next File
{
/*
Do something here
Ex. using cout << FindData.ftCreationTime << endl;
will display the creation time of the current file.
*/
}
FindClose(hFind);
/* //Options specifically for what your asking for.
FindData.ftCreationTime
FindData.ftLastAccessTime
FindData.ftLastWriteTime
*/
return 0;
}
real quick so might have made some errors.
Thanks - Managed to write this code for visual C++ compiler. I now need to use this info to create a series of windows directories?
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <time.h>
#include <conio.h>
int main(void)
{
char buf1[80];
time_t filecreate;
struct tm *ptr;
struct _finddata_t c_file;
long hfile;
if ((hfile = _findfirst("D:\\*.c",&c_file)) == 1L)
printf("a");
else
{
printf("%-12s %.24s % 9ld\n",c_file.name,ctime(&(c_file.time_write)),c_f ile.size);
filecreate = ctime(&(c_file.time_write));
}
_findclose(hfile);
}