Pliki_SOP/zajecia11/lab_ls.c

34 lines
527 B
C
Raw Permalink Normal View History

2019-01-10 12:00:32 +01:00
#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;
}