Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <Windows.h>
- #include <fstream>
- #include <filesystem>
- 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);
- SetConsoleOutputCP(1251);
- //создание пустой директории
- filesystem::create_directory("C:/Users/PC/Desktop/temp");
- //создание директории с подкаталогами
- filesystem::create_directories("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5");
- ofstream fout("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");
- //удаление пустой папки с помощью remove
- filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5");
- fout4.close();
- //удаление файла с помощью remove (не забываем закрыть файл)
- 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");
- fout.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/temp34", filesystem::copy_options::recursive);
- //удаление папки с подкаталогами и файлами
- filesystem::remove_all("C:/Users/PC/Desktop/temp34");
- //определить размер файла
- cout << filesystem::file_size("C:/Users/PC/Desktop/file3.txt") << endl;
- //определить является ли объект файлом
- cout << filesystem::is_regular_file("C:/Users/PC/Desktop/file3.txt") << endl;
- //определить является ли объект папкой
- cout << filesystem::is_directory("C:/Users/PC/Desktop/temp33") << endl;
- //вывести содержимое папки
- print_directory("C:/Users/PC/Desktop");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement