Jeremiah_

SO SC-C

Sep 30th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <sys/syscall.h>
  8. #include <dirent.h>
  9. #include <string.h>
  10.  
  11. int main()
  12. {    
  13.     DIR *dr = opendir("./");
  14.     struct dirent *fl; //Struct para receber as informações do diretório
  15.     int len;
  16.     char ans[301];
  17.  
  18.     if(dr == NULL)
  19.     {
  20.         puts("ERROR");
  21.         exit(0);
  22.     }
  23.  
  24.     while( fl = readdir(dr) ) //Lê cada arquivo do diretório
  25.     {
  26.         strcpy( ans + 1, fl -> d_name ); //Copia o nome do arquivo pra uma var
  27.         ans[0] = 'L'; //Add "L" antes do nome
  28.         rename( fl -> d_name, ans); //Novo nome do arquivo
  29.     }
  30.     puts("DONE");
  31.     exit(1);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment