Thread: Checking if char *path; is a valid directory.

  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
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    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, 03: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, 04:45 AM
  3. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM
  4. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM

Tags for this Thread