如何检查C语言在Linux上是否存在目录?
您可以使用opendir()并检查是否ENOENT == errno失败:
opendir()
ENOENT == errno
#include <dirent.h> #include <errno.h> DIR* dir = opendir("mydir"); if (dir) { /* Directory exists. */ closedir(dir); } else if (ENOENT == errno) { /* Directory does not exist. */ } else { /* opendir() failed for some other reason. */ }