34 lines
527 B
C
34 lines
527 B
C
|
#include <dirent.h>
|
||
|
#include <errno.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <stdio.h>
|
||
|
#include <unistd.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
|
||
|
int main(int argc, char** argv)
|
||
|
{
|
||
|
DIR *dir;
|
||
|
struct dirent *entry;
|
||
|
char cwd[1000];
|
||
|
|
||
|
if (getcwd(cwd, sizeof(cwd)) == NULL)
|
||
|
perror("getcwd() error");
|
||
|
|
||
|
if (argc == 2)
|
||
|
strcpy(cwd, argv[1]);
|
||
|
|
||
|
if ((dir = opendir(cwd)) == NULL)
|
||
|
perror("blad opendir");
|
||
|
else
|
||
|
{
|
||
|
printf("Dir: %s\n", cwd);
|
||
|
while ((entry = readdir(dir)) != NULL)
|
||
|
printf(" %s\n", entry ->d_name);
|
||
|
|
||
|
closedir(dir);
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|