Guest User

Untitled

a guest
Jul 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include "interface.h"
  2.  
  3. static int one(struct dirent *unused){
  4. return 1;
  5. }
  6.  
  7. /****************************************
  8. * Busca arquivo passado como paramentro
  9. * na lista de arquivos
  10. ***************************************/
  11. int fexists(char *file, struct dirent **eps, int n){
  12. int i;
  13. for(i=0; i < n; i++)
  14. if(!strcmp(file, eps[i]->d_name))
  15. return 1;
  16. return 0;
  17. }
  18.  
  19.  
  20. //opcao para o usuario escolher arquivo
  21. void user_option(){
  22. struct dirent **eps;
  23. int n;
  24. char file[20];
  25.  
  26. //armazena nomes de arquivos do diretorio
  27. n = scandir ("./", &eps, one, alphasort);
  28. printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
  29. printf("\t\tArquivos locais:\n");
  30. printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
  31. if (n >= 0){
  32. int cnt;
  33. for(cnt = 0; cnt < n; ++cnt)
  34. if(cnt%2==0)
  35. printf("%s\n", eps[cnt]->d_name);
  36. }
  37. else
  38. perror("Couldn't open the directory");
  39.  
  40. printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
  41. printf("\n\nQual arquivo deseja consultar? ");
  42. scanf("%s", file);
  43.  
  44. if( fexists(file, eps, n) )
  45. printf("\nArquivo %s esta presente no diretorio corrente.\n", file);
  46. else
  47. printf("\nArquivo nao esta presente. Busca deve ser iniciada.\n");
  48. }
Add Comment
Please, Sign In to add comment