Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <Windows.h>
- #include <filesystem>
- using namespace std;
- void PrintDirectory(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");
- //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"); // удаление файла
- fout3.close();
- //filesystem::remove_all("C:/Users/PC/Desktop/temp/temp2/1"); // удаление папки со всем содержимым
- //filesystem::rename("C:/Users/PC/Desktop/temp/temp2/1/2/3/4", "C:/Users/PC/Desktop/temp/temp2/1/2/3/33"); // переименование пустой папки
- fout.close();
- fout2.close();
- //filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Desktop/temp35"); // переименование папки с файлами (не забыть закрыть вложенные файлы)
- //filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Downloads/temp"); // перемещение папки с файлами (не забыть закрыть вложенные файлы)
- //filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Downloads/temp35"); // перемещение папки с файлами с переименованием (не забыть закрыть вложенные файлы)
- //filesystem::copy("C:/Users/PC/Desktop/temp/temp2/1/2/3/33", "C:/Users/PC/Desktop/33"); // копирование пустой папки (аналогично файл)
- //filesystem::copy("C:/Users/PC/Desktop/temp", "C:/Users/PC/Desktop/temp44", filesystem::copy_options::recursive); // копирование папки с содержимым
- //cout << filesystem::file_size("C:/Users/PC/Desktop/file.txt") << endl; // определить размер файла
- //cout << filesystem::is_directory("C:/Users/PC/Desktop/temp") << endl; // определить что объект является папкой
- //cout << filesystem::is_regular_file("C:/Users/PC/Desktop/file.txt") << endl; // определить что объект является файлом
- PrintDirectory("C:/Users/PC/Desktop");
- }
Advertisement
Add Comment
Please, Sign In to add comment