Checking if char *path; is a valid directory.

This is a discussion on Checking if char *path; is a valid directory. within the C Programming forums, part of the General Programming Boards category; Hey, For what I saw in man stat(), opendir(char *dir_path); will return null if isn't a directory what it's trying ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    7

    Question Checking if char *path; is a valid directory.

    Hey,

    For what I saw in man stat(), opendir(char *dir_path); will return null if isn't a directory what it's trying to open, right? So should I use this to test for a valid directory on dir_path char pointer? Maybe there is some better method I can use.


    [ ]'s
    regards

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    Code:
    struct stat myFile;
    if (stat(fileName, &myFile) < 0)
    {
        // Doesn't exist
    }
    else if (!S_ISDIR(myFile.st_mode))
    {
        // Exists but is not a directory
    }

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    7
    nice, thanks!


    [ ]'s
    regards

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling GNU MP
    By mattnp12 in forum C Programming
    Replies: 3
    Last Post: 06-23-2011, 04:58 PM
  2. Char Help! "Packing " bits to a signle unsigned char
    By xxrexdartxx in forum C Programming
    Replies: 7
    Last Post: 10-11-2009, 05:45 AM
  3. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 06:59 AM
  4. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 10:05 AM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 12:57 PM

Tags for this Thread


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