标签:boost filesystem
#include<boost/filesystem.hpp>
{
boost::filesystem::path path("/test/test1"); //初始化
boost::filesystem::path old_cpath=boost::filesystem::current_path(); //取得当前目录
boost::filesystem::path file_path = old_cpath / "file"; //path支持重载/运算符
if(boost::filesystem::exists(file_path)) //判断文件存在性
{
std::string strPath = file_path.string();
int x = 1;
}
else
{
//目录不存在;
boost::filesystem::create_directory(file_path); //目录不存在,创建
}
bool bIsDirectory = boost::filesystem::is_directory(file_path); //判断file_path是否为目录
boost::filesystem::recursive_directory_iterator beg_iter(file_path);
boost::filesystem::recursive_directory_iterator end_iter;
for (; beg_iter != end_iter; ++beg_iter)
{
if (boost::filesystem::is_directory(*beg_iter))
{
continue;
}
else
{
std::string strPath = beg_iter->path().string(); //遍历出来的文件名
int x=1;
}
}
boost::filesystem::path new_file_path = file_path / "test.txt";
if(boost::filesystem::is_regular_file(new_file_path)) //判断是否为普通文件
{
UINT sizefile = boost::filesystem::file_size(new_file_path); //文件大小(字节)
int x =1;
}
boost::filesystem::remove(new_file_path);//删除文件new_file_path
}标签:boost filesystem
原文地址:http://blog.csdn.net/qingzai_/article/details/44412727