#include <iostream>
#include <filesystem>
#include <fstream>
int main()
{
// Create a new directory
std::filesystem::create_directory("test_dir");
// Create a new file in the directory
std::ofstream file("test_dir/test_file.txt");
file << "Hello, World!";
file.close();
// Check if the file exists
if (std::filesystem::exists("test_dir/test_file.txt")) {
std::cout << "The file exists." << std::endl;
} else {
std::cout << "The file does not exist." << std::endl;
}
// Get the file size
std::cout << "File size: " << std::filesystem::file_size("test_dir/test_file.txt") << " bytes" << std::endl;
// Get the file modification time
std::filesystem::file_time_type modification_time = std::filesystem::last_write_time("test_dir/test_file.txt");
std::cout << "Modification time: " << modification_time << std::endl;
// Get file permissions
std::filesystem::perms permissions = std::filesystem::status("test_dir/test_file.txt").permissions();
std::cout << "Permissions: " << std::oct << permissions << std::endl;
// Rename the file
std::filesystem::rename("test_dir/test_file.txt", "test_dir/renamed_file.txt");
// Remove the directory and its contents
std::filesystem::remove_all("test_dir");
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: