Advertisement
paulogp

Listar directoria

Jul 14th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. // Apple Xcode
  2. // paulogp
  3.  
  4. /* listagem de directoria */
  5. #include <stdio.h>
  6. #include <unistd.h>
  7.  
  8. #define MAXC 255
  9.  
  10. int main (int argc, const char * argv[])
  11. {
  12.     char the_buffer[MAXC];
  13.     int the_no_files = 0;
  14.    
  15.     FILE *the_fp = popen("ls", "r");
  16.    
  17.     sleep(500); // for buffer (opcional)
  18.    
  19.     while (fgets(the_buffer, MAXC, the_fp) != NULL)
  20.     {
  21.         printf("%s", the_buffer);
  22.         the_no_files += 1;
  23.     }
  24.    
  25.     printf("%d ficheiros\n", the_no_files);
  26.    
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement