C++文件系统

filesystem

#include <filesystem>
#include <iostream>
using namespace std;
int main()
{
	//打开文件夹
	filesystem::path url("file");
	//判断当前文件夹是否存在
	if (!filesystem::exists(url))
	{
		cout << "相对路径文件夹不存在" << endl;
	}
	//创建单层文件夹,路径存在不做其他操作
	filesystem::create_directory("file");
	//存储错误信息
	error_code err;
	//将文件夹是否创建成功的信息存入
	filesystem::create_directory("file/x", err);
	//将存储的错误信息打印出来
	cout << err.message() << endl;
	//创建多层文件夹
	filesystem::create_directories("sss/ss/s", err);
	cout << err.message() << endl;
	//删除根文件夹
	filesystem::remove_all(url);
	//获取文件最后一次的操作时间
	auto time = filesystem::last_write_time("sss");
	//获取时间戳
	cout << time.time_since_epoch().count() << endl;
	//获取当前路径
	filesystem::path CUR = filesystem::current_path();
	cout << CUR<< endl;
	cout << CUR.root_directory() << endl;//根目录
	cout <<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值