Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <string>
  5. #include <fcntl.h>
  6. #include <dirent.h>
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h> //chmod
  11. #include <cstring>
  12. #include <algorithm>
  13.  
  14.  
  15.  
  16. using namespace std;
  17.  
  18. void listujPliki(const char *nazwa_sciezki, const char *nazwa_pliku)
  19. {
  20. cout<<nazwa_sciezki<<" "<<nazwa_pliku<<endl;
  21. struct dirent * plik;
  22. DIR * sciezka;
  23. sciezka = opendir( nazwa_sciezki);
  24. size_t count;
  25. int file = open(nazwa_pliku, O_WRONLY, 0600);
  26. while(( plik = readdir( sciezka ))!= NULL )
  27. {
  28. count = strlen(plik->d_name);
  29. write(file,plik->d_name,count);
  30. cout<<plik->d_name<<endl;
  31. }
  32. closedir(sciezka);
  33. close(file);
  34. }
  35.  
  36. int main(int argc, char *argv[])
  37. {
  38.  
  39. if(argv[1] == NULL)
  40. {
  41. cout<<"Nie podano zadnego argumentu "<<endl;
  42. return 0;
  43. }
  44. else
  45. {
  46.  
  47. char *nazwa = argv[1];
  48. int fd = open(nazwa,O_RDONLY,O_WRONLY);
  49. if(fd != -1)
  50. {
  51. cout<<"Istnieje juz plik o takiej samej nazwie "<<endl;
  52. close(fd);
  53. }
  54. else
  55. {
  56.  
  57. creat(nazwa, 7777);
  58. if(argc > 1 )
  59. listujPliki(argv[1],nazwa);
  60. else
  61. listujPliki(".", nazwa);
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement