开发者

How to check whether a folder or a file is hidden=

开发者 https://www.devze.com 2023-01-04 05:53 出处:网络
I want to find out whether a file or a directory is hide. At first I made use of CFile::GetStatus(), however I found this api sometimes will return FALSE.

I want to find out whether a file or a directory is hide.

At first I made use of CFile::GetStatus(), however I found this api sometimes will return FALSE.

I don't know开发者_Go百科 why, So I wrote the following code, However I found it is not stable. What is wrong with my code?

  BOOL IsHide(const CString& strPath, BOOL& bIsHide)
  {
   if (strPath.GetLength() <= 3)
   {
    bIsHide = FALSE;
    return  TRUE;
   }
   bIsHide = FALSE;
   HANDLE hFile = CreateFile( strPath, 0, FILE_SHARE_READ,
    NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,
    NULL);
   if (hFile == INVALID_HANDLE_VALUE)
   {
    ASSERT(FALSE);
    return FALSE;
   }
   BY_HANDLE_FILE_INFORMATION fiBuf;  
   GetFileInformationByHandle( hFile, &fiBuf );
   CloseHandle(hFile);
   WORD isHide = (fiBuf.dwFileAttributes) | FILE_ATTRIBUTE_HIDDEN;
   if (isHide == fiBuf.dwFileAttributes)
   {
    bIsHide = TRUE;
   }
   else
   {
    bIsHide = FALSE;
   }
   return TRUE;
}


Use GetFileAttributes function.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号