Get Meta-Data

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?

Speedy
Hi,

Can you please be specific about the environment?So that we can give a try to think a solution based on that.
closed account (z05DSL3A)
Assuming Windows API: GetFileTime Function

see: http://msdn.microsoft.com/en-us/library/ms724320(VS.85).aspx

===========================================

If CLR (.net), use a File objects GetCreationTime member

Along the lines of:
 
DateTime dt = File.GetCreationTime( /* String^ */ path);

Last edited on
DateTime dt = File.GetCreationTime( /* String^ */ path);, by Grey wolf

Yes, If Speedy knows where the file is(File path), then this will be the shortest solution.
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.
The environment is MS Visual Studio C++, with Framework 3.0
and yes, I know where the file is placed ;)

THX for your help :)
Last edited on
Topic archived. No new replies allowed.