Determine file/folder in C
问题 I have the following code in C: DIR *mydir = opendir("/"); struct dirent *entry = NULL; while((entry = readdir(mydir))) { printf("%s\n", entry->d_name); //printf("%i\n", entry->d_type); } closedir(mydir); It works and shows the files/folders in the location, correctly. However, I want to tell if it is a folder or a file. How can I do this? I tried with d_type (as you can see on the code) but no success. 回答1: Use stat(): struct stat st; stat("nodename", &st); int isDirectory = S_ISDIR(st.st