Function: check if it's a directory

This is a discussion on Function: check if it's a directory within the Windows Programming forums, part of the Platform Specific Boards category; Hi all! Is there a Windows function that check me if it's a directory? If it doesn't exist, is there ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    5

    Question Function: check if it's a directory

    Hi all! Is there a Windows function that check me if it's a directory? If it doesn't exist, is there a mode?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Or even more succintly
    PathIsDirectory Function (Windows)

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    5
    thank you both!

    For other user that they will have same problem, this is the solution:
    Code:
    ...
    isDirectory = GetFileAttributes( struttura.cFileName );
    if ( isDirectory == FILE_ATTRIBUTE_DIRECTORY )
    cout << "it's a dir" << endl;
    else 
    cout << "it isn't a dir" << endl;
    ....

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    It's still wrong -> File Attribute Constants (Windows)
    The result is a bit-mask, so your example would fail for a hidden directory.

    You need to do
    Code:
    isDirectory = GetFileAttributes( struttura.cFileName ); 
    if ( ( isDirectory & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY )
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Quote Originally Posted by Francesco Leone View Post
    Code:
    isDirectory = GetFileAttributes( struttura.cFileName );
    You do realise the attributes of the file/folder are present in the dwFileAttributes member of the WIN32_FIND_DATA structure?

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Francesco Leone View Post
    Hi all! Is there a Windows function that check me if it's a directory? If it doesn't exist, is there a mode?
    Use the PathIsDirectory() function...

    Obviously if it doesn't exist the PathIsDirectory() function is going to return false...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Check if a directory exist?
    By kevinawad in forum C++ Programming
    Replies: 12
    Last Post: 10-26-2008, 02:42 AM
  2. How can i check a directory for certain files?
    By patrioticpar883 in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 04:27 PM
  3. Check directory program is run from?
    By willc0de4food in forum C Programming
    Replies: 10
    Last Post: 06-29-2005, 02:36 AM
  4. Check if file is a directory
    By cristane in forum C Programming
    Replies: 3
    Last Post: 06-16-2005, 02:58 PM
  5. How to check a directory is exist or not?
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 03-23-2002, 09:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21