-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectory_listing.c
More file actions
39 lines (30 loc) · 920 Bytes
/
directory_listing.c
File metadata and controls
39 lines (30 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
void directory_listing(char *path){
struct stat stat_buffer;
struct dirent *ent;
DIR *dir;
dir = opendir (path);
if (dir == NULL) {
perror (""); exit(1); }
printf ("\nKatalogen %s:\n", path);
printf ("------------------------------------\n");
printf ("Rettigheter\tUID\tGID\tNavn\n");
printf ("------------------------------------\n");
while ((ent = readdir (dir)) != NULL) {
stat (ent->d_name, &stat_buffer);
if((strcmp(ent->d_name, ".") != 0)
&& (strcmp(ent->d_name, "..") != 0))
{
printf ("%o\t\t", stat_buffer.st_mode & 0777 ); // Retigheter
printf ("%d\t", stat_buffer.st_uid); // Eier bruker (id)
printf ("%d\t", stat_buffer.st_gid); // Eier gruppe (id)
printf ("%s\n", ent->d_name); // filnavn
}
}
closedir (dir);
}