Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <fcntl.h>
- #include <dirent.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h> //chmod
- #include <cstring>
- #include <algorithm>
- using namespace std;
- void listujPliki(const char *nazwa_pliku)
- {
- struct dirent * plik;
- DIR * sciezka;
- sciezka = opendir(".");
- size_t count;
- int file = open(nazwa_pliku, O_WRONLY, 0600);
- while(( plik = readdir(sciezka))!= NULL )
- {
- count = strlen(plik->d_name);
- write(file,plik->d_name,count);
- }
- closedir(sciezka);
- close(file);
- }
- int main(int argc, char *argv[])
- {
- if(argc <= 1)
- {
- cout<<"Nie podano zadnego argumentu "<<endl;
- return 0;
- }
- else
- {
- char *nazwa = argv[1];
- int fd = open(nazwa,O_RDONLY,O_WRONLY);
- if(fd != -1)
- {
- cout<<"Istnieje juz plik o takiej samej nazwie "<<endl;
- close(fd);
- }
- else
- {
- creat(nazwa, 7777);
- listujPliki(nazwa);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement