在C中确定文件/文件夹 [英] Determine file/folder in C
本文介绍了在C中确定文件/文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在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.
但是,我想知道它是文件夹还是文件.我怎样才能做到这一点?我尝试使用d_type(如您在代码中看到的),但没有成功.
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.
推荐答案
查看全文