Hello
I've got a problem!
I need to know the exact time when a txt-file was created.
The txt-file contains temporary data from an other programm, but I don't know when the data is in the file.
Is anybody out there how can give me an answer how I can manage this?
Assuming MFC:
First To retrieve the current directory or executable name at run time. and then the time diff between creation time and overwritten time will decide when a data is added to the file.
As some of executable are independent / doesn’t attached to any particular directory. So for safe side, it should be consider good programming practice, if you find the said information on run time, the benefits includes, hard coding folder path or crash occurring due to non existent folder location.
Algorithm includes:
1: GetModuleFileName Api, passing NULL (for current module), which will return current executable path in it second parameter (szCurrentModulePath in above case).
2: We will convert the normal character array into CString object, for easier string manipulation, as it has many handy functions for string manipulation.
3:Now we try to retrieve the last Backslash, as we know, folder and filenames are separated by backslash, and after backslash the file path contain the filename.
4: Based on above we can easily get the current directory and filename, by seaching and retrieving part of string we want to.
5:Than use the GetFileTime function to retrieve the last-write time for a file. It converts the time to local time based on the current time-zone settings, and creates a date and time string that can be shown to the user.
6:Make a comparison with last written time with current time,If mismatch than you can get the time when it's over written.