C语言编写读目录程序代码
C语言编写读目录程序代码
#include <stdio.h>
#include <dirent.h>
int main()
{
DIR *dirptr = NULL;
struct dirent *entry;
if((dirptr = opendir(argv[1])) == NULL)
{
printf{\"open dir !\"};
return 1;
}
else
{
while (entry = readdir(dirptr))
{
printf(\"%s\\n\", entry);
}
closedir(dirptr);
}
return 0;
}