刚开始用
BOOL GetFileAttributesEx(
  LPCTSTR lpFileName, 
  GET_FILEEX_INFO_LEVELS fInfoLevelId, 
  LPVOID lpFileInformation 
);
但第二个参数不知道怎么搞都不行
后来用 GetFileTime又没搞定,大家出个主意.

解决方案 »

  1.   

    这个 可以 GET几个TIME呀??
    文件有 访问时间 修改时间 创建时间.....
    楼主 加油哦
      

  2.   

    #include <windows.h>// GetLastWriteTime - Retrieves the last-write time and converts
    //                    the time to a string
    //
    // Return value - TRUE if successful, FALSE otherwise
    // hFile      - Valid file handle
    // lpszString - Pointer to buffer to receive stringBOOL GetLastWriteTime(HANDLE hFile, LPTSTR lpszString)
    {
        FILETIME ftCreate, ftAccess, ftWrite;
        SYSTEMTIME stUTC, stLocal;    // Retrieve the file times for the file.
        if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
            return FALSE;    // Convert the last-write time to local time.
        FileTimeToSystemTime(&ftWrite, &stUTC);
        SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);    // Build a string showing the date and time.
        wsprintf(lpszString, TEXT("%02d/%02d/%d  %02d:%02d"),
            stLocal.wMonth, stLocal.wDay, stLocal.wYear,
            stLocal.wHour, stLocal.wMinute);    return TRUE;
    }
      

  3.   

    GetFileAttributesEx 这个函数的第二个参数用 GetFileExInfoStandard 即可.
    即:
    TCHAR *filename = TEXT("C:\\src\\win32\\sdk\\LeafEditor\\update.txt");
    WIN32_FILE_ATTRIBUTE_DATA pFileInfo;
    GetFileAttributesEx(filename, GetFileExInfoStandard, &pFileInfo);
      

  4.   

    直接监视文件更改不更好?马上就知道更改了  
       
    FindFirstChangeNotificationThe FindFirstChangeNotification function creates a change notification handle and sets up initial change notification filter conditions. A wait on a notification handle succeeds when a change matching the filter conditions occurs in the specified directory or subtree. The function does not report changes to the specified directory itself.This function does not indicate the change that satisfied the wait condition. To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function.
    HANDLE FindFirstChangeNotification(
      LPCTSTR lpPathName,
      BOOL bWatchSubtree,
      DWORD dwNotifyFilter
    );Parameters
    lpPathName 
    [in] Pointer to a null-terminated string that specifies the path of the directory to watch. 
    In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.Windows Me/98/95:  This string must not exceed MAX_PATH characters.
    bWatchSubtree 
    [in] Specifies whether the function will monitor the directory or the directory tree. If this parameter is TRUE, the function monitors the directory tree rooted at the specified directory; if it is FALSE, it monitors only the specified directory. 
    dwNotifyFilter 
    [in] Filter conditions that satisfy a change notification wait. This parameter can be one or more of the following values. Value Meaning 
    FILE_NOTIFY_CHANGE_FILE_NAME Any file name change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a file name. 
    FILE_NOTIFY_CHANGE_DIR_NAME Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory. 
    FILE_NOTIFY_CHANGE_ATTRIBUTES Any attribute change in the watched directory or subtree causes a change notification wait operation to return. 
    FILE_NOTIFY_CHANGE_SIZE Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed. 
    FILE_NOTIFY_CHANGE_LAST_WRITE Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed. 
    FILE_NOTIFY_CHANGE_SECURITY Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return. Return Values
    If the function succeeds, the return value is a handle to a find change notification object.If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.Res
    The wait functions can monitor the specified directory or subtree by using the handle returned by the FindFirstChangeNotification function. A wait is satisfied when one of the filter conditions occurs in the monitored directory or subtree.After the wait has been satisfied, the application can respond to this condition and continue monitoring the directory by calling the FindNextChangeNotification function and the appropriate wait function. When the handle is no longer needed, it can be closed by using the FindCloseChangeNotification function.
    Symbolic link behavior—If the path points to a symbolic link, the notification handle is created for the target.If an application has registered to receive change notifications for a directory that contains symbolic links, the application is only notified when the symbolic links have been changed, not the target files.
    Transacted OperationsIf there is a transaction associated with the thread at the time of the call, then that transaction is bound to the change notification handle that is returned. The change notifications that are found through enumeration on the notification handle follows the appropriate isolation rules.
    Example Code 
    For an example, see Obtaining Directory Change_Notifications. Requirements
    Client Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95. 
    Server Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server. 
    Header Declared in Winbase.h; include Windows.h.
     
    Library Use Kernel32.lib.
     
    DLL Requires Kernel32.dll.  
    Unicode Implemented as FindFirstChangeNotificationW (Unicode) and FindFirstChangeNotificationA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
     See Also
    Directory Management Functions
    FindCloseChangeNotification
    FindNextChangeNotification
    ReadDirectoryChangesW
    Symbolic LinksSend comments about this topic to MicrosoftRequirements
    Client Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95. 
    Server Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server. 
    Header Declared in Winbase.h; include Windows.h.
     
    Library Use Kernel32.lib.
     
    DLL Requires Kernel32.dll.  
    Unicode Implemented as FindFirstChangeNotificationW (Unicode) and FindFirstChangeNotificationA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode.
     
    See Also
    Directory Management Functions
    FindCloseChangeNotification
    FindNextChangeNotification
    ReadDirectoryChangesW
    Symbolic LinksSend comments about this topic to Microsoft
      

  5.   

    SDK的例子:
      
     
    Obtaining Directory Change Notifications
    An application can monitor the contents of a directory and its subdirectories by using change notifications. Waiting for a change notification is similar to having a read operation pending against a directory and, if necessary, its subdirectories. When something changes within the directory being watched, the read operation is completed. For example, an application can use these functions to update a directory listing whenever a file name within the monitored directory changes.
    An application can specify a set of conditions that trigger a change notification by using the FindFirstChangeNotification function. The conditions include changes to file names, directory names, attributes, file size, time of last write, and security. This function also returns a handle that can be waited on by using the wait functions. If the wait condition is satisfied, FindNextChangeNotification can be used to provide a notification handle to wait on subsequent changes. The FindCloseChangeNotification function closes the notification handle. However, these functions do not indicate the actual change that satisfied the wait condition.To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function. This function also enables you to provide a completion routine.To track changes on a volume, see change journals.The following example monitors the directory tree for directory name changes. It also monitors a directory for file name changes. The example uses the FindFirstChangeNotification function to create two notification handles and the WaitForMultipleObjects function to wait on the handles. Whenever a directory is created or deleted in the tree, the example should update the entire directory tree. Whenever a file is created or deleted in the directory, the example should refresh the directory.
    #include <windows.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <tchar.h>void RefreshDirectory(LPTSTR);
    void RefreshTree(LPTSTR);void WatchDirectory(LPTSTR lpDir)
    {
       DWORD dwWaitStatus; 
       HANDLE dwChangeHandles[2]; 
       TCHAR lpDrive[4];
       TCHAR lpFile[_MAX_FNAME];
       TCHAR lpExt[_MAX_EXT];   _tsplitpath(lpDir, lpDrive, NULL, lpFile, lpExt);   lpDrive[2] = (TCHAR)'\\';
       lpDrive[3] = (TCHAR)'\0';
     
    // Watch the directory for file creation and deletion. 
     
       dwChangeHandles[0] = FindFirstChangeNotification( 
          lpDir,                         // directory to watch 
          FALSE,                         // do not watch subtree 
          FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes 
     
       if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) 
          ExitProcess(GetLastError()); 
     
    // Watch the subtree for directory creation and deletion. 
     
       dwChangeHandles[1] = FindFirstChangeNotification( 
          lpDrive,                       // directory to watch 
          TRUE,                          // watch the subtree 
          FILE_NOTIFY_CHANGE_DIR_NAME);  // watch dir. name changes 
     
       if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) 
          ExitProcess(GetLastError()); 
     
    // Change notification is set. Now wait on both notification 
    // handles and refresh accordingly. 
     
       while (TRUE) 
       { 
       // Wait for notification.
     
          dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, 
             FALSE, INFINITE); 
     
          switch (dwWaitStatus) 
          { 
             case WAIT_OBJECT_0: 
     
             // A file was created or deleted in the directory.
             // Refresh this directory and restart the notification.
     
                RefreshDirectory(lpDir); 
                if ( FindNextChangeNotification( 
                        dwChangeHandles[0]) == FALSE ) 
                    ExitProcess(GetLastError()); 
                break; 
     
             case WAIT_OBJECT_0 + 1: 
     
             // A directory was created or deleted in the subtree.
             // Refresh the tree and restart the notification.
     
                RefreshTree(lpDrive); 
                if (FindNextChangeNotification( 
                        dwChangeHandles[1]) == FALSE) 
                    ExitProcess(GetLastError()); 
                break; 
     
            default: 
                ExitProcess(GetLastError()); 
          }
       }
    }void RefreshDirectory(LPTSTR lpDir)
    {
       _tprintf(TEXT("Refresh the directory (%s).\n"), lpDir);
    }void RefreshTree(LPTSTR lpDrive)
    {
       _tprintf(TEXT("Refresh the directory tree (%s).\n"), lpDrive);
    }
    Send comments about this topic to Microsoft