From: http://www.averainy.info/c_yu_yan_pan_duan_mu_lu_shi_fou_cun_zai_like-unix/
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> int main(int argc,char *argv[]) { struct stat filestat; if(argc != 2) { printf("Usage ./a.out argv1\n"); exit(-1); } if(stat(argv[1], &filestat) != 0) { perror(argv[1]); return -1; } if(S_ISDIR(filestat.st_mode)) printf("%s is dir \n",argv[1]); else printf("%s is not dir\n",argv[1]); }