我有什么做的是列出目录内的所有文件。
如果一个目录显示,那么它也应该打印出该目录内的文件。
目前,我有:
DIR *directory;
struct dirent *files;
char folderPath[] = "//home//unix//20//";
// Make sure I can open the folder "test" otherwise throw an error
if ((directory = opendir(folderPath)) == NULL)
{
printf("\nCouldn't Open Folder!\n");
return 0;
}
// Loop around and check if the directory is another directory
int i = 0;
while ((files = readdir(directory)) != NULL)
{
//printf("%s\n", files->d_name);
if (files->d_name
i++;
}
printf("\n");
此代码打印出该目录内的所有文件和文件夹。
我现在需要做的是找出如果d_name是一个目录,如果是这样,打印出该目录内的内容。
一些人帮我,我怎么能做到这一点?
谢| Willtwinny