-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlf.c
37 lines (30 loc) · 773 Bytes
/
lf.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
/* This is the main function how scan the dirs*/
void listfiles(const char *path) {
struct dirent *entry;
DIR *dp = opendir(path);
if (dp == NULL) {
perror("opendir");
return;
}
while ((entry = readdir(dp))) {
printf("\x1b[32m" "%s ", entry->d_name);
}
closedir(dp);
}
int main(int argc, char *argv[]){
if (argc != 2) {
char cwd[1024]; // Assuming a reasonable buffer size
getcwd(cwd, sizeof(cwd)); // if you don't write The path to the target dir it will just scan the working dir
listfiles(cwd);
}
else{
char *path = argv[1];
listfiles(path);
}
return 0;
}