|
[code:1]
#include <dirent.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
DIR *dirp;
struct dirent entry, *ptr;
if (argc != 2)
{
printf("Usage: %s <dirname>\n", argv[0]);
return 1;
}
if ((dirp = opendir(argv[1])) == NULL)
{
printf("%s : opendir error\n", argv[0]);
return 1;
}
do
{
readdir_r(dirp, &entry, &ptr);
printf("%s\n", ptr->d_name);
} while (ptr != NULL);
closedir(dirp);
return 0;
}[/code:1] |
|