CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    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...


  2. #2
    Join Date
    May 1999
    Location
    13 N 77 E
    Posts
    183

    Re: checking whether a name is file or directory

    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


  3. #3
    Join Date
    Apr 1999
    Posts
    396

    Re: checking whether a name is file or directory

    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


  4. #4
    Join Date
    May 1999
    Location
    13 N 77 E
    Posts
    183

    Re: checking whether a name is file or directory

    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
    };




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