get last access time

This is a discussion on get last access time within the C++ Programming forums, part of the General Programming Boards category; how can ı get last access time without framework?? ı know GetLastAccessTime(file) but it runs on framework.....

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    44

    get last access time

    how can ı get last access time without framework?? ı know GetLastAccessTime(file) but it runs on framework..

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by koyboy View Post
    how can ı get last access time without framework?? ı know GetLastAccessTime(file) but it runs on framework..
    Since getting the access time is not part of the C++ standard, there is no way to do it without relying on a "framework." On Windows you can use GetFileTime(), on POSIX systems you can use stat() or fstat().

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    44
    thank you so much.. but ı have one more problem.. ı get it but ı want compare first and second file.. smaller or bigger??.. but if ı write in "if(deneme1>deneme2)" ı get problem.. ı think ı must convert to other file because ı get time in FILETIME... can you give advice??

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    44
    I GET THIS ERROR

    --------------------Configuration: ccc - Win32 Debug--------------------
    Compiling...
    ccc.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\ccc\ccc.cpp(285) : error C2664: 'ctime' : cannot convert parameter 1 from 'struct _FILETIME *' to 'const long *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\ccc\ccc.cpp(285) : error C2664: 'ctime' : cannot convert parameter 1 from 'struct _FILETIME *' to 'const long *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.

    ccc.exe - 2 error(s), 0 warning(s)

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, FILETIME from Microsofts API is not the same as "time_t" for example.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    How about showing us the code you are using that generates these errors?

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    44
    Code:
    FILETIME son,temptime;
    if(ilk==0)
    		{
    			ilk++;
    			GetFileTime(&hFind,NULL,NULL,&son);			
    
    		}
    		GetFileTime(&hFind,NULL,NULL,&temptime);		
    		if(ctime(&temptime)>ctime(&son))
    sory.. ı wrote it..

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    As long as the files you are comparing are on the same system, you should be able to compare the time by simply moving the low and high part of the FILETIME (described here:http://msdn.microsoft.com/en-us/libr...84(VS.85).aspx) into a ULARGE_INTEGER, and then compare the quadpart of the ULARGE_INTEGER variables.

    If you are using getting files from a network, you could also need to (potentially - but this starts to get very tricky) for the possibility that the files are in different timezones and/or the systems have different system times set.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,597
    Dot your 'i's, bozo!
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    44
    I couldn't do this can anybody help to me?? I write simple example about my code :

    Code:
    FILETIME son,temptime;
    SYSTEMTIME sonn,temptimee,soN,temptimE;
    ......
    GetFileTime(&hFind,NULL,NULL,&son);
    FileTimeToSystemTime(&son, &sonn);
    SystemTimeToTzSpecificLocalTime(NULL, &sonn, &soN);
    ......
    GetFileTime(&hFind,NULL,NULL,&temptime);
    FileTimeToSystemTime(&temptime, &temptimee);
    SystemTimeToTzSpecificLocalTime(NULL, &temptimee, &temptimE);
    can we compare soN and temptimE with if?? like this:

    Code:
    if(temptimE>soN)
    MessageBox(NULL, FindFileData.cFileName, "UYARI", NULL);
    ofcourse this is false

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    They aren't helping because you are posting on the wrong forum! You are asking a platform specific question on the forum for people who write portable code (or so the theory goes).

    [edit] I am making this function special, just for you [/code]

    Example:
    Code:
    #include <string>
    #include <cstring>
    #include <windows.h>
    #include <ctime>
    /* Note that by including windows.h you should automatically be directing
     * questions to the windows forums, not this one.
     */
    
    #define MAGICAL1  11644473600
    #define MAGICAL2  10000000
    
    time_t GetLastAccessTime(const std::string &filename)
    {
        time_t t = 0;
        ULARGE_INTEGER uli;
        FILETIME ft;
    
        HANDLE hFile = CreateFile(filename.c_str(), GENERIC_READ, 0, 0, 0, OPEN_EXISTING, 0, 0);
    
        if(hFile != INVALID_HANDLE)
        {
            BY_HANDLE_FILE_INFORMATION info;
    
            if(GetFileInformationByHandle(hFile, &info))
            {
                FileTimeToLocalFileTime(&info.ftLastAccessTime, &ft);
                uli.HighPart = ft.ftLastAccessTime.dwHighDateTime;
                uli.LowPart = ft.ftLastAccessTime.dwLowDateTime;
    
                uli.QuadPart /= MAGICAL2;
                t = (time_t)(uli.QuadPart - MAGICAL1);
            }
    
            CloseFile(hFile);
        }
    
        return t;
    }
    I changed it only because it allows you to be portable. Now you are posting on the correct forum
    Last edited by master5001; 05-08-2008 at 06:03 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Times I'm getting
    By afflictedd2 in forum Linux Programming
    Replies: 8
    Last Post: 07-23-2008, 07:18 AM
  2. Real time access to display image
    By abachler in forum Windows Programming
    Replies: 3
    Last Post: 07-21-2008, 05:30 PM
  3. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 05:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21