Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timestamps

Status
Not open for further replies.

Ma3x323

Programmer
Jun 27, 2001
148
US
Hello,
Wondering how you can get a timestamp from a certain file. I need it to simulate the makemake utility which needs the timestamps for the files so it can recognize which ones have been modified.
Need it to be compatible in all OS platforms.

Thanks in advance -Feryl
--> Just a silly software engineer wannabee.
If you feel a post has been helpful to you, click on the link at the bottom of their post to cast a vote for "TipMaster Of The Week". You don't need to be the one who asked the question to vote.
 
see _getsystime in time.h Ion Filipski
1c.bmp


filipski@excite.com
 
Does that function gets the system time or the time the file was last modified. I also thought that each file would contain a time stamp somewhere and maybe parse it. But I don't where it is. -Feryl
--> Just a silly software engineer wannabee.
If you feel a post has been helpful to you, click on the link at the bottom of their post to cast a vote for "TipMaster Of The Week". You don't need to be the one who asked the question to vote.
 
I wasn't attentive. In windows you can use GetFileTime, is compatible with many file systems, but not very compatible with different Operating Systems. Put this question in Unix C++ forum. OS independent code you can make only in Java. Ion Filipski
1c.bmp


filipski@excite.com
 
OK. I am not a big windows programmer. Just in school still and most of my projects are command prompt/ dos based. So I am wondering what #include would be needed and how the function works. Maybe a little code?? Sorry to bother. Thanks a lot.
-Feryl
--> Just a silly software engineer wannabee.
If you feel a post has been helpful to you, click on the link at the bottom of their post to cast a vote for "TipMaster Of The Week". You don't need to be the one who asked the question to vote.
 
#include<windows.h>
......
FILETAME CreationTime, LastAccessTime, LastWriteTime;
BOOL x = GetFileTime(
hFile,&CreationTime,&LastAccessTime,&LastWriteTime);
Ion Filipski
1c.bmp


filipski@excite.com
 
If you want OS independence use the C runtime library.

This should work for UNIX, Windows, and DOS going back several revs.

#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>

.
.
.
struct _stat s;

if ( 0 == _stat( &quot;c:\\somepath\\somefile.ext&quot;, &s ) ) {
/* the files's last modified time is in s.st_mtime */
}
else {
/* error - file probably doesn't exist */
}
.
.
.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top