Subversion Repositories Kolibri OS

Rev

Rev 8744 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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