Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //g++ lista.cpp -o lista && ./lista
- #include <unistd.h>
- #include <dirent.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <errno.h>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <iostream>
- using namespace std;
- int main()
- {
- int ofile;
- char nazwa[255];
- while (1)
- {
- cout<<"Podaj nazwe pliku"<<endl;
- cin>>nazwa;
- ofile= open(nazwa,O_APPEND|O_WRONLY|O_CREAT|O_EXCL,0600);
- if (ofile==-1)
- {
- if (errno==EEXIST)
- {
- cout<<"ERROR "<<EEXIST<<" EEXIST:plik już istnieje; podaj inn▒^▒ nazw▒^▒"<<endl;
- }
- else cout<<"Inny blad\n";
- }
- else break;
- }
- string nazwyPlikow[1000];
- struct dirent *plik;
- DIR * sciezka;
- int iloscPlikow=0;
- if (sciezka=opendir("."))
- {
- while (plik=readdir(sciezka))
- {
- if (strcmp(plik->d_name,nazwa)==0) continue;
- string temp=plik->d_name;
- nazwyPlikow[iloscPlikow]=temp+"\n";
- iloscPlikow++;
- }
- closedir(sciezka);
- }
- sort(nazwyPlikow, nazwyPlikow+iloscPlikow);
- for (int i=0; i<iloscPlikow; i++)
- {
- const char *temp = nazwyPlikow[i].c_str();
- write(ofile,temp,strlen(temp));
- }
- close(ofile);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement