File time

Hello,

I'm having a small prob w/ the following code. Could anyone plz take a look at it and tell me what may cause the problem?

Basically, I'm trying to read from a file that was created most recently.
I'm using CompareFileTime() function, but for odd reason, CompareFileTime() always returns 0 in this case. :(

1
2
3
4
5
6
7
8
9
10
11
12
                  ifstream test1("a.txt");
                  ifstream test2("b.txt");

		FILETIME tCreate, tAccess, t1Write, t2Write;
		
		GetFileTime(test1,&tCreate,&tAccess,&t1Write);
		GetFileTime(test2,&tCreate,&tAccess,&t2Write);
		
		if(CompareFileTime(&t1Access,&t2Access) > 0)
                       cout << "Read from a";
                  else
                       cout << "Read from b";


Thanks!
Eh... wrong forum... GetFileTime() as far as I know is from the Windows API...

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

Example of proper usage:
http://msdn.microsoft.com/en-us/library/ms724926(v=VS.85).aspx

GetFileTime requires an input of type HANDLE, which isn't the same as ifstream, is it?

-Albatross

oh I see.
So by the way, is there any simple way to get writing time of an ifstream object?
closed account (S6k9GNh0)
I think that the given information was enough for you to have figured it out. Files are handled different on every OS and as so, each file is given different attributes and properties. To access these, you must go through the OS in some fashion.
Last edited on
So by the way, is there any simple way to get writing time of an ifstream object?
No. Neither C nor C++ provide interfaces to get file attributes. You have to fallback to system calls. See the links Albatross posted.
Topic archived. No new replies allowed.