Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <io.h>
- #include <windows.h>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- using namespace std;
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // FUNKCJA PRZYJMUJACA SCIEZKE DO FOLDERU I ZWRACAJACA TABLICE (VECOTR) Z NAZWAMI PODFOLDEROW //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- vector <string> findDir(string path)
- {
- path += "\\*";
- vector <string> subdir;
- _finddata_t fileData;
- const char *address = path.c_str();
- long handler = _findfirst(address, &fileData);
- if (handler != (-1))
- {
- string fileName;
- int findNext;
- do
- {
- fileName = fileData.name;
- if (fileData.attrib == _A_SUBDIR && fileName != "." && fileName != "..")
- {
- subdir.push_back(fileName);
- }
- findNext = _findnext(handler, &fileData);
- }
- while (!findNext);
- _findclose(handler);
- _findclose(findNext);
- }
- else
- _findclose(handler);
- return subdir;
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // FUNKCJA PRZYJMUJACA SCIEZKE DO FOLDERU ORAZ ROZSZERZENIE PLIKOW I ZWRACAJACA TABLICE (VECOTR) //
- // Z NAZWAMI PLIKOW O ZADANYM ROZSZERZENIU //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- vector <string> findFiles(string path, string extension)
- {
- path += "\\*" + extension;
- vector <string> ourFiles;
- _finddata_t fileData;
- const char *address = path.c_str();
- long handler = _findfirst(address, &fileData);
- if (handler != (-1))
- {
- string fileName; // = fileData.name;
- //ourFiles.push_back(fileName);
- int findNext; // = _findnext(handler, &fileData);
- do
- {
- fileName = fileData.name;
- ourFiles.push_back(fileName);
- findNext = _findnext(handler, &fileData);
- }
- while (!findNext);
- _findclose(handler);
- _findclose(findNext);
- }
- else
- {
- cout << "Brak plikow o zadanym rozszerzeniu" << endl;
- _findclose(handler);
- }
- return ourFiles;
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- // FUNKCJA PRZYJMUJACA SCIEZKE DO PLIKU I ZWRACAJACA LICZBE LITER W PLIKU //
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- int linesCount(string path)
- {
- int numOFletters = 0;
- string line;
- ifstream myFile(path);
- if (myFile.good())
- {
- while (getline(myFile, line))
- {
- //cout << line.size() << endl;
- for (int i = 0; i < line.size(); i++)
- {
- if ( (int(line.at(i)) >= 65 && int(line.at(i)) <= 90) || (int(line.at(i)) >= 97 && int(line.at(i)) <= 122))
- {
- ++numOFletters;
- }
- }
- }
- return numOFletters;
- }
- else
- return -1;
- }
- int main()
- {
- string plik = "D:\\Elektronika i Telekomunikacja\\V semestr\\JPO\\Projekt\\test.txt";
- cout << linesCount(plik) << endl;
- string path = "D:\\Elektronika i Telekomunikacja\\V semestr\\JPO\\Projekt";
- string ext = ".txt";
- vector <string> sciezka;
- sciezka = findFiles(path, ext);
- for (int i = 0; i < findFiles(path, ext).size(); i++)
- {
- cout << findFiles(path, ext)[i] << endl;
- }
- sciezka = findDir(path);
- for (int i = 0; i < findDir(path).size(); i++)
- {
- cout << findDir(path)[i] << endl;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement