Q: Which WinAPI function can be used to open a folder?
A: To open a folder we can use CreateFile like for any file, but additionally we have to set FILE_FLAG_BACKUP_SEMANTICS flag.
Here is an example that opens a folder then gets its creation date:
Code:DWORD GetDirectoryCreationTime(LPCTSTR pszDir, FILETIME& ft) { DWORD dwRet = NO_ERROR; HANDLE hFile = ::CreateFile(pszDir, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, // required if open a directory NULL); if(INVALID_HANDLE_VALUE == hFile) { dwRet = ::GetLastError(); } else { if(!::GetFileTime(hFile, &ft, NULL, NULL)) { dwRet = ::GetLastError(); } ::CloseHandle(hFile); } return dwRet; }




Reply With Quote
