boost::filesystem常用用法详解

时间:2015-03-18 18:09:54   收藏:0   阅读:498

提示:

#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  
}


原文:http://blog.csdn.net/qingzai_/article/details/44412727

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!