File Times Without Modifying Last Access
|
|
Currently this program only performs two simple functions:
1.) To list a file's Create, Modified and Access dates and times without changing
the last Access date to today, as is done when using the properties function of
Windows Explorer
2.) To write the file data to a Microsoft Heirarchical Flexgrid
To download all of the files to run this program in MS Visual C++,
click "FileTimes.zip"
|
This program could easily be expanded to return file size and other file properties.
Also I will probably expand this code to recursively run thru directory structures.
To see a sample of recursive directory expansion, click here
To e-mail a suggestion or comment click on: sam@gilcrist.com
Return to www.gilcrist.com
void CFileInventoryDlg::OnOK()
{
/***********************************************************************************
Author : R. Sam Gilcrist
Date : 12 Mar 2003
Purpose : ON_OK, find the system times of a file, and display them in a flex grid
***********************************************************************************/
char sFileName [1025] ;
char sCreate [125];
char sAccess [125];
char sMod [125];
//Read the form to get the file name
UpdateData(true);
strcpy(sFileName,m_sFileName);
//Create an instance of the File Inventory class
CFileInv * cInv = new CFileInv();
//Pass the file name in and pointers to the file date variables
cInv->GetFileTimes(sFileName,sCreate,sAccess,sMod);
//Load the data into a ms hierarchical flexgrid
m_cGrid.SetRow(1);
m_cGrid.SetCol(1);
m_cGrid.SetText(sFileName);
m_cGrid.SetCol(2);
m_cGrid.SetText(sCreate);
m_cGrid.SetCol(3);
m_cGrid.SetText(sMod);
m_cGrid.SetCol(4);
m_cGrid.SetText(sAccess);
}
void CFileInv::GetFileTimes(char *sFile, char *sCreate, char *sAccess, char *sMod)
{
/***********************************************************************************
Author : R. Sam Gilcrist
Date : 12 Mar 2003
Purpose : Given a file name, return a string for each of the file times
Note
: The times listed will be translated into Local Time and may not reflect the times
: the file were saved, modified, and accessed originally if the saving and detecting
:are done in different time zone
***********************************************************************************/
WIN32_FIND_DATA fd = {0};
HANDLE hFile = FindFirstFile(sFile, &fd);
FILETIME ftCreate, ftAccess, ftWrite;
SYSTEMTIME stUTC, stLocal;
char ATime[125];
char WTime[125];
char CTime[125];
ftCreate = fd.ftCreationTime;
ftAccess = fd.ftLastAccessTime;
ftWrite = fd.ftLastWriteTime;
FileTimeToSystemTime(&ftAccess, &stUTC);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
ConvertDateToString(stLocal,ATime);
FileTimeToSystemTime(&ftCreate, &stUTC);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
ConvertDateToString(stLocal,CTime);
FileTimeToSystemTime(&ftWrite, &stUTC);
SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
ConvertDateToString(stLocal,WTime);
strcpy(sCreate, CTime);
strcpy(sAccess, ATime);
strcpy(sMod,WTime);
return;
}
void CFileInv::ConvertDateToString(SYSTEMTIME &stLocal, char *sTime)
{
/***********************************************************************************
Author : R. Sam Gilcrist
Date : 12 Mar 2003
Purpose : Given a Sytem Time variable, return a string
***********************************************************************************/
char sDay[3];
char sMonth[3];
char sYear[4];
char sHr[3];
char sMin[3];
char sSec[3];
itoa(stLocal.wMonth,sMonth,10);
strcpy(sTime,sMonth);
strcat(sTime,"/");
itoa(stLocal.wDay,sDay,10);
strcat(sTime,sDay);
strcat(sTime,"/");
itoa(stLocal.wYear,sYear,10);
strcat(sTime,sYear);
strcat(sTime," ");
itoa(stLocal.wHour,sHr,10);
strcat(sTime, sHr);
strcat(sTime,":");
itoa(stLocal.wMinute,sMin,10);
strcat(sTime,sMin);
strcat(sTime,":");
itoa(stLocal.wSecond, sSec,10);
strcat(sTime,sSec);
return;
}