35657

Untitled

Dec 2nd, 2023
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <Windows.h>
  5. #include <filesystem>
  6.  
  7. using namespace std;
  8.  
  9. void PrintDirectory(const string& str) {
  10.     for (const auto a : filesystem::directory_iterator(str)) {
  11.         cout << a.path().filename().string() << endl;
  12.     }
  13. }
  14.  
  15. int main() {
  16.     SetConsoleCP(1251);
  17.     SetConsoleOutputCP(1251);
  18.  
  19.     filesystem::create_directory("C:/Users/PC/Desktop/temp"); // создание папки
  20.  
  21.     filesystem::create_directories("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5"); // создание папки с вложенными папками
  22.  
  23.     ofstream fout("C:/Users/PC/Desktop/temp/file.txt"); // создаем файл в новой папке
  24.  
  25.     ofstream fout2("C:/Users/PC/Desktop/temp/temp2/file2.txt");
  26.     ofstream fout3("C:/Users/PC/Desktop/temp/temp2/1/file3.txt");
  27.     ofstream fout4("C:/Users/PC/Desktop/temp/temp2/1/2/file4.txt");
  28.  
  29.     //filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/3/4/5"); // удаление пустой папки
  30.  
  31.     fout4.close(); // не забываем закрыть файл перед удалением
  32.  
  33.     //filesystem::remove("C:/Users/PC/Desktop/temp/temp2/1/2/file4.txt"); // удаление файла
  34.  
  35.     fout3.close();
  36.  
  37.     //filesystem::remove_all("C:/Users/PC/Desktop/temp/temp2/1"); // удаление папки со всем содержимым
  38.  
  39.     //filesystem::rename("C:/Users/PC/Desktop/temp/temp2/1/2/3/4", "C:/Users/PC/Desktop/temp/temp2/1/2/3/33"); // переименование пустой папки
  40.  
  41.     fout.close();
  42.     fout2.close();
  43.  
  44.     //filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Desktop/temp35"); // переименование папки с файлами (не забыть закрыть вложенные файлы)
  45.  
  46.     //filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Downloads/temp"); // перемещение папки с файлами (не забыть закрыть вложенные файлы)
  47.  
  48.     //filesystem::rename("C:/Users/PC/Desktop/temp", "C:/Users/PC/Downloads/temp35"); // перемещение папки с файлами с переименованием (не забыть закрыть вложенные файлы)
  49.  
  50.     //filesystem::copy("C:/Users/PC/Desktop/temp/temp2/1/2/3/33", "C:/Users/PC/Desktop/33"); // копирование пустой папки (аналогично файл)
  51.  
  52.     //filesystem::copy("C:/Users/PC/Desktop/temp", "C:/Users/PC/Desktop/temp44", filesystem::copy_options::recursive); // копирование папки с содержимым
  53.  
  54.     //cout << filesystem::file_size("C:/Users/PC/Desktop/file.txt") << endl; // определить размер файла
  55.  
  56.     //cout << filesystem::is_directory("C:/Users/PC/Desktop/temp") << endl; // определить что объект является папкой
  57.  
  58.     //cout << filesystem::is_regular_file("C:/Users/PC/Desktop/file.txt") << endl; // определить что объект является файлом
  59.  
  60.     PrintDirectory("C:/Users/PC/Desktop");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment