2022-04-15 11:11:49 +02:00
|
|
|
#include <conio.h>
|
2021-05-25 17:38:14 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2022-04-15 11:11:49 +02:00
|
|
|
#include <sys/dir.h>
|
|
|
|
#include <sys/dirent.h>
|
2021-05-25 17:38:14 +02:00
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
const char* folder_type = "Folder";
|
|
|
|
const char* file_type = "File";
|
2021-05-25 17:38:14 +02:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2022-04-15 11:11:49 +02:00
|
|
|
char* path = getcwd(NULL, PATH_MAX);
|
|
|
|
printf("Current directory: %s\n", path);
|
|
|
|
if (mkdir("test")) {
|
|
|
|
puts("Test folder created!");
|
|
|
|
} else {
|
2021-05-25 17:38:14 +02:00
|
|
|
puts("Error creating folder!");
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
|
|
|
|
DIR* mydir = opendir(path);
|
|
|
|
if (!mydir) {
|
2021-05-25 17:38:14 +02:00
|
|
|
puts("File system error.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
struct dirent* file_info;
|
|
|
|
char* str_type = NULL;
|
2021-05-25 17:38:14 +02:00
|
|
|
putc(' ');
|
2022-04-15 11:11:49 +02:00
|
|
|
while ((file_info = readdir(mydir)) != NULL) {
|
|
|
|
if (file_info->d_type == IS_FOLDER) {
|
2021-05-25 17:38:14 +02:00
|
|
|
(*con_set_flags)(CON_COLOR_GREEN);
|
|
|
|
str_type = (char*)folder_type;
|
2022-04-15 11:11:49 +02:00
|
|
|
} else {
|
2021-05-25 17:38:14 +02:00
|
|
|
(*con_set_flags)(7);
|
|
|
|
str_type = (char*)file_type;
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
printf("%3d %20s %s\n ", file_info->d_ino, file_info->d_name, str_type);
|
2021-05-25 17:38:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
setcwd("/sys/develop");
|
2022-04-15 11:11:49 +02:00
|
|
|
path = getcwd(NULL, PATH_MAX);
|
2021-05-25 17:38:14 +02:00
|
|
|
printf("Move to the directory: %s\n", path);
|
|
|
|
free(path);
|
|
|
|
}
|