CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    171

    Number of days between two filetime structures...

    I'm basically trying to see if a file is a certain number of days old, so that I can delete it... the code so far looks like:

    Code:
    	FILETIME ft;
    	FILETIME ftFile;
    
    	bFinished = FALSE;
    
    	_snprintf(szSearch, sizeof(szPath), "%s\\*.*", szPath);
    	hSearch = FindFirstFile(szSearch, &wfd);
    
    	if (hSearch == INVALID_HANDLE_VALUE)
    		return FALSE;
    
    
    	while (!bFinished) {
    		if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
    			_snprintf(szFileName, sizeof(szFileName),
    				"%s\\%s", szPath, wfd.cFileName);
    
    
    			GetSystemTimeAsFileTime(&ft);
    			
    			ftFile.dwHighDateTime = wfd.ftLastWriteTime.dwHighDateTime;
    			ftFile.dwLowDateTime = wfd.ftLastWriteTime.dwLowDateTime;
    
    			LocalFileTimeToFileTime(&(wfd.ftLastWriteTime));
    
    /*NEED TO COMPARE HERE */
    
    
    			if (!DeleteFile(szFileName)) {
    				;
    			}
    		}
    
    
    		if (!FindNextFile(hSearch, &wfd)) {
    			if (GetLastError() == ERROR_NO_MORE_FILES) {
    				bFinished = TRUE;
    			}
    			else {
    				;
    				break;
    			}
    		}
    	}
    
    	if (!FindClose(hSearch)) {
    		;
    	}
    
    
    	return TRUE;

    This code is not complete I know ... I need to be able to tell how many days old the file is, how do i get this from two FILETIME objects??

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757

    Re: Number of days between two filetime structures...

    One solution is GetFileInformationByHandle().

    Kuphryn

  3. #3
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Number of days between two filetime structures...

    Code:
    FILETIME ft1, ft2;
    COleDateTime ot1(ft1);
    COleDateTime ot2(ft2);
    COleDateTimeSpan otspan = ot2-ot1;
    otspan.GetTotalDays();
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured