1

I would like to check the existance of a directory. I recive just "yes" even though the directory doesn't exists. what should I do? Thank you very much!

int main()
{
if(opendir("dsfdsgfdsgrs") == NULL)
   printf("%s","no");
else
   printf("%s","yes");

return 0;
}
Maria Popa
  • 43
  • 6

1 Answers1

1

This example works

#include <stdio.h>
#include <dirent.h>

int main(int argc, char ** argv)
{
    DIR *dir;

    dir = opendir("folder");
    if (dir == NULL) {
        printf("Couldn't open dir\n");
    } else {
        printf("Opened dir\n");
    }

    if (dir != NULL)
        closedir(dir);
}
Naveen
  • 459
  • 4
  • 10