Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <filesystem>
- #include <windows.h>
- using namespace std;
- // вывод содержимого директории с указанием размера для файлов
- void PrintDirectoryInfo(const string& str) { // указываем путь к папке
- for (const auto& a : filesystem::directory_iterator(str)) { // обход всех файлов в директории
- string name = a.path().filename().string();
- string full_name = str + '/' + name;
- cout << setw(30) << name;
- if (filesystem::is_regular_file(full_name)) {
- cout << " " << setw(10) << filesystem::file_size(full_name) << " byte";
- }
- cout << endl;
- }
- }
- int DirectorySize(const string& str) { // указываем путь к папке
- int size = 0;
- for (const auto& a : filesystem::directory_iterator(str)) { // обход всех файлов в директории
- string full_name = str + '/' + a.path().filename().string();
- if (filesystem::is_regular_file(full_name)) {
- size += filesystem::file_size(full_name);
- }
- if (filesystem::is_directory(full_name)) {
- size += DirectorySize(full_name);
- }
- }
- return size;
- }
- void FindName(const string& find_name, const string& find_catalogue) {
- for (const auto& a : filesystem::directory_iterator(find_catalogue)) {
- string name = a.path().filename().string();
- string full_name = find_catalogue + '/' + name;
- if (name == find_name) {
- cout << full_name << endl;
- }
- if (filesystem::is_directory(full_name)) {
- FindName(find_name, full_name);
- }
- }
- }
- void FindNameMask(const string& find_name, const string& find_catalogue) {
- for (const auto& a : filesystem::directory_iterator(find_catalogue)) {
- string name = a.path().filename().string();
- string full_name = find_catalogue + '/' + name;
- if (name.find(find_name) != string::npos) {
- cout << full_name << endl;
- }
- if (filesystem::is_directory(full_name)) {
- FindNameMask(find_name, full_name);
- }
- }
- }
- int main() {
- SetConsoleCP(1251); // установка кодировки 1251 в поток ввода
- SetConsoleOutputCP(1251); // установка кодировки 1251 в поток вывода
- PrintDirectoryInfo("C:/Users/PC/Desktop");
- cout << "======================" << endl;
- cout << DirectorySize("C:/Users/PC/Desktop") << endl;
- cout << "======================" << endl;
- FindName("решения", "C:/Users/PC/Desktop");
- cout << "======================" << endl;
- FindNameMask("решения", "C:/Users/PC/Desktop");
- }
Advertisement
Add Comment
Please, Sign In to add comment