-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsols.c
45 lines (42 loc) · 795 Bytes
/
sols.c
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
39
40
41
42
43
44
45
#include "shell.h"
int sols(int argc,char *argv[])
{
struct stat f1;
struct dirent **namelist;
int n;
if(argc < 1)
{
return 0;
}
else if (argc == 1)
{
n = scandir(".",&namelist,NULL,alphasort);
}
else
{
n = scandir(argv[1], &namelist, NULL, alphasort);
}
if(n < 0)
{
perror("scandir");
return 0;
}
else
{
while (n--)
{
stat(namelist[n]->d_name, &f1);
if(S_ISDIR(f1.st_mode) && (0 != strcmp(".", namelist[n]->d_name)) && (0 != strcmp("..", namelist[n]->d_name)))
{
printf("%s%s%s%s\n", BOLD, CYAN, namelist[n]->d_name, NORMAL);
}
else if(S_ISREG(f1.st_mode))
{
printf("%s\n", namelist[n]->d_name);
}
free(namelist[n]);
}
free(namelist);
}
return 1;
}