Subversion Repositories Kolibri OS

Rev

Rev 8793 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <sys/dir.h>
  5. #include <sys/dirent.h>
  6.  
  7. const char* folder_type = "Folder";
  8. const char* file_type = "File";
  9.  
  10. int main()
  11. {
  12.     char* path = getcwd(NULL, PATH_MAX);
  13.     printf("Current directory: %s\n", path);
  14.     if (mkdir("test")) {
  15.         puts("Test folder created!");
  16.     } else {
  17.         puts("Error creating folder!");
  18.     }
  19.  
  20.     DIR* mydir = opendir(path);
  21.     if (!mydir) {
  22.         puts("File system error.");
  23.         return -1;
  24.     }
  25.  
  26.     struct dirent* file_info;
  27.     char* str_type = NULL;
  28.     putc(' ');
  29.     while ((file_info = readdir(mydir)) != NULL) {
  30.         if (file_info->d_type == IS_FOLDER) {
  31.             (*con_set_flags)(CON_COLOR_GREEN);
  32.             str_type = (char*)folder_type;
  33.         } else {
  34.             (*con_set_flags)(7);
  35.             str_type = (char*)file_type;
  36.         }
  37.         printf("%3d  %20s  %s\n ", file_info->d_ino, file_info->d_name, str_type);
  38.     };
  39.  
  40.     setcwd("/sys/develop");
  41.     path = getcwd(NULL, PATH_MAX);
  42.     printf("Move to the directory: %s\n", path);
  43.     free(path);
  44. }
  45.