Click to See Complete Forum and Search --> : checking whether a name is file or directory
hi,
My problem is when i open a file dialog box before opening any file i should get the file name to display preview.
but i could not make out the selected file is file or directory. Because GETFILENAME() will give the file in the
edit box . even if i click on a directory previously selected file name remains in edit box.
please suggest me suitable solution for this..
thanks and regards..
dasaradh...
muscicapa
May 26th, 1999, 08:20 AM
CFileFind::IsDirectory
BOOL IsDirectory( ) const;
Return Value
Nonzero if successful; otherwise 0.
Remarks
Call this member function to determine if the found file is a directory. A file that is a directory is marked with FILE_ATTRIBUTE_DIRECTORY a file attribute identified in theWIN32_FIND_DATA structure.
from MSDN
Todd Jeffreys
May 26th, 1999, 10:09 AM
But that requires a full operation of CFileFind, which is unnecessary. You should be able to use ::GetFileAttributes(LPCTSTR lpszFile) and get those attributes in one call. Then you can check
if (GetFileAttributes(file) & FILE_ATTRIBUTE_DIRECTORY) // it's a directory
muscicapa
May 26th, 1999, 10:59 PM
You r right, It also appears this can be done with the CFile member GetStatus
which returns a CFileStatus reference with an attribute m_attribute byte which can be checked bitwise
The m_attribute is the file attribute. The Microsoft Foundation classes provide an enum type attribute so that you can specify attributes symbolically:
BOOL GetStatus( CFileStatus& rStatus ) const;
static BOOL PASCAL GetStatus( LPCTSTR lpszFileName, CFileStatus& rStatus );
CFileStatus
The CFileStatus structure has the following fields:
CTime m_ctime The date and time the file was created.
CTime m_mtime The date and time the file was last modified.
CTime m_atime The date and time the file was last accessed for reading.
LONG m_size The logical size of the file in bytes, as reported by the DIR command.
BYTE m_attribute The attribute byte of the file.
char m_szFullName[_MAX_PATH] The absolute filename in the Windows character set.
enum Attribute {
normal = 0x00,
readOnly = 0x01,
hidden = 0x02,
system = 0x04,
volume = 0x08,
directory = 0x10,
archive = 0x20
};
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.