Last active
June 6, 2018 11:48
-
-
Save PiotrWegrzyn/dd3a443ef14725778031dd2529bd9b87 to your computer and use it in GitHub Desktop.
Systemy - Posortowana lista plików w folderze do pliku.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
} | |
} | |
DIR *currentDirectory = opendir("."); //otwiera aktualna sciezke katalogu | |
std::vector <std::string> files; //tworzymy vector string | |
struct dirent * files_count = 0; | |
while(files_count = readdir(currentDirectory)){ | |
std::string fileName = files_count->d_name; //pomocniczy string | |
files.push_back(fileName); //dopisujemy do stringa ktory potem jest dodawany do pliku | |
} | |
closedir(currentDirectory); | |
std::sort(files.begin(), files.end()); //sortujemy wlasciwy string | |
for (int i = 0; i < files.size(); ++i) { | |
std::string fileName = files[i]; | |
write(write_file, fileName.c_str(), fileName.length()); | |
//powyzej wpisujemy stringa zwierajacego nazwe pliku o dlugosci takiej jaka ma string | |
write(write_file, "\n", 1); //dopisujemy enter | |
} | |
close(write_file); | |
cout << "do pliku zapisano:" << endl; | |
int fileDesc = open(argv[1], O_RDONLY); | |
char character; | |
while(read(fileDesc, &character, 1)) | |
cout<<character; | |
close(fileDesc); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment