CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    98

    accessing file time structures without MFC?

    I wrote a little unix-like "touch" utility to reset file timestamps to the current time... but I used MFC headers to access the structure. I've been looking through the msdn trying to find a way to do this without MFC, so I can put the function into a regular dll, but I haven't found anything yet. Anyone know what classes/methods to use in the winapi or ansi c++ to access/mutate file timestamps?

    Sam.

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: accessing file time structures without MFC?

    are you talking about those api File Times ?

    Cheers

  3. #3
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: accessing file time structures without MFC?

    Here's the OK button handler from a dialog app I wrote a while ago that updates the created/accessed/modified times for a given file (error checking removed):
    Code:
    case ID_OK:
    {
    	// Get the name of the file...
    	TCHAR szFile[MAX_PATH] = {0};
    	GetWindowText(GetDlgItem(hwnd, IDC_FILENAME), szFile, sizeof(szFile) / sizeof(TCHAR));
    
    	// Get each of the date/time values...
    	SYSTEMTIME st = {0};
    	st.wMonth  = GetDlgItemInt(hwnd, IDC_MONTH, NULL, FALSE);
    	st.wDay    = GetDlgItemInt(hwnd, IDC_DAY,   NULL, FALSE);
    	st.wYear   = GetDlgItemInt(hwnd, IDC_YEAR,  NULL, FALSE);
    	st.wHour   = GetDlgItemInt(hwnd, IDC_HOUR,  NULL, FALSE);
    	st.wMinute = GetDlgItemInt(hwnd, IDC_MIN,   NULL, FALSE);
    
    	// Convert the SYSTEMTIME to a FILETIME...
    	FILETIME ft = {0};
    	SystemTimeToFileTime(&st, &ft);
    
    	// Write the new filetime...
    	HANDLE hFile = CreateFile(szFile, FILE_WRITE_ATTRIBUTES, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    	SetFileTime(hFile, &ft, &ft, &ft);
    	CloseHandle(hFile);
    
    	return FALSE;
    }
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  4. #4
    Join Date
    Feb 2005
    Posts
    98

    Re: accessing file time structures without MFC?

    haha... yeah, i found all that stuff in the MSDN after i posted this. disregard this thread...

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