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 print_directory(const string& str) {
- for (const auto& a : filesystem::directory_iterator(str)) {
- cout << a.path().filename().string() << endl;
- }
- }
- int main() {
- SetConsoleCP(1251); // установка кодировки 1251 в поток ввода
- SetConsoleOutputCP(1251); // установка кодировки 1251 в поток вывода
- filesystem::create_directory("C:/Users/PC/Desktop/temp"); // создание папки
- filesystem::create_directories("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5"); // создание папки с подпапкамм
- ofstream fout1("C:/Users/PC/Desktop/temp/file.txt");
- ofstream fout2("C:/Users/PC/Desktop/temp/temp2/file2.txt");
- ofstream fout3("C:/Users/PC/Desktop/temp/temp2/1/file3.txt");
- ofstream fout4("C:/Users/PC/Desktop/temp/temp2/1/2/file4.txt");
- filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5"); // удалить пустую папку
- fout4.close();
- filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/file4.txt"); // удалить файл
- filesystem::rename("C:/Users/PC/Desktop/temp/temp2/1/2/3/4", "C:/Users/PC/Desktop/temp/temp2/1/2/3/5"); // переименование пустой папки
- fout1.close();
- fout2.close();
- fout3.close();
- filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Desktop/temp33"); // переименование папки с файлами и каталогами (закрыть файлы, которые лежат в этом каталоге)
- filesystem::copy("C:/Users/PC/Desktop/temp33/temp2/1/file3.txt", "C:/Users/PC/Desktop/file3.txt"); // копирование файла (исходный файл остается на месте)
- filesystem::copy("C:/Users/PC/Desktop/temp33", "C:/Users/PC/Desktop/temp34"); // копирование папки с файлами
- filesystem::copy("C:/Users/PC/Desktop/temp33", "C:/Users/PC/Desktop/temp35", filesystem::copy_options::recursive); // копирование папки с файлами и подкаталогами
- filesystem::remove_all("C:/Users/PC/Desktop/temp35"); // удаление папки с подкаталогами и файлами
- cout << filesystem::file_size("C:/Users/PC/Desktop/file3.txt") << endl; // узнать размер файла
- cout << filesystem::is_regular_file("C:/Users/PC/Desktop/file3.txt") << endl; // возвращает true если объект является файлом
- cout << filesystem::is_directory("C:/Users/PC/Desktop/file3.txt") << endl; // возвращает true если объект является каталогом
- cout << filesystem::is_directory("C:/Users/PC/Desktop/temp33") << endl; // возвращает true если объект является каталогом
- print_directory("C:/Users/PC/Desktop");
- }
Advertisement
Add Comment
Please, Sign In to add comment