Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 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_pliku)
  19. {
  20. struct dirent * plik;
  21. DIR * sciezka;
  22. sciezka = opendir(".");
  23. size_t count;
  24. int file = open(nazwa_pliku, O_WRONLY, 0600);
  25. while(( plik = readdir(sciezka))!= NULL )
  26. {
  27. count = strlen(plik->d_name);
  28. write(file,plik->d_name,count);
  29.  
  30. }
  31. closedir(sciezka);
  32. close(file);
  33. }
  34.  
  35. int main(int argc, char *argv[])
  36. {
  37.  
  38. if(argc <= 1)
  39. {
  40. cout<<"Nie podano zadnego argumentu "<<endl;
  41. return 0;
  42. }
  43. else
  44. {
  45.  
  46. char *nazwa = argv[1];
  47. int fd = open(nazwa,O_RDONLY,O_WRONLY);
  48. if(fd != -1)
  49. {
  50. cout<<"Istnieje juz plik o takiej samej nazwie "<<endl;
  51. close(fd);
  52. }
  53. else
  54. {
  55. creat(nazwa, 7777);
  56. listujPliki(nazwa);
  57.  
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement