boost::filesystem 库(文件系统)
2016-07-14 17:44
337 查看
filesystem 库是一个可移植的文件按系统操作库。可以跨平台操作目录、文件等。
后面还有:
迭代目录功能
查找文件··
拷贝目录··
#include <boost/filesystem.hpp> using namespace boost::filesystem; #include <iostream> using namespace std; void os_test() { path p1("./a_dir"); cout << p1 << endl; path p2("d:/boost/test.txt"); cout << p2 << endl; p1 /= "etc"; //使用operator/=追加路径 cout << p1 << endl; p1.append("test.txt"); //追加 cout << p1 << endl; path p3("./"); p3 = system_complete("./"); cout << p3 << endl; //返回路径在当前文件系统中的完整路径。 path p4("../"); cout << system_complete(p4) << endl; cout << p2.string() << endl; cout << p2.parent_path() << endl; //父路径 cout << p2.stem() << endl; //不含扩展名的全路径名 cout << p2.filename() << endl; //文件名 cout << p2.extension() << endl; //扩展名 cout << p2.root_name() << endl; cout << p2.root_directory() << endl; cout << p2.root_path() << endl; //根路径 //判断路径是否有文件名 if (p3.has_filename()){ cout << "has file " << endl; } else{ cout << "dont has file" << endl; } cout << p2 << endl; cout << p2.replace_extension("ldd") << endl; //变更文件扩展名 //cout<<p2.remove_filename() << endl; //删除路径中最后的文件名 //文件异常 try{ cout<<file_size(p2); } catch (filesystem_error& e){ cout << e.what() << endl; cout << e.path1() << endl; } // path p5 = initial_path(); //exe所在路径 cout << p5 << endl; cout << current_path() << endl; //当前文件路径 try{ cout << file_size(p5) << endl; } catch (filesystem_error& e){ cout << e.what() << endl; cout << e.path1() << endl; } int GB = 1024 * 1024 * 1024; space_info si = space("d:/"); //磁盘空间分配情况 cout << si.capacity/GB << ends << si.available/GB << ends << si.free/GB << endl; //使用path对象打开一个文本文件,并打印到标准输出上。 path p6("d:/filesystem_test.txt"); ifstream ifs(p6.string()); cout << ifs.rdbuf(); }
后面还有:
迭代目录功能
查找文件··
拷贝目录··
相关文章推荐
- boost相关小知识(长期顶置更新)
- C++单元测试:boost.test
- boost asio学习笔记 [1] - 同步通讯
- boost_asio学习笔记[2] - 客户端异步通讯
- boost::flat_map性能测试
- Ubuntu下如何安装boost?
- How to get a boost::shared_ptr from this
- boost 库 enable_shared_from_this 实现原理分析
- boost bind使用指南
- 最常用的两种C++序列化方案的使用心得
- 使用boost进行CRC64计算
- [网络开发]boost::asio简介
- Windows下如何编译使用boost?
- Boost库学习(0)
- Boost库学习(1)log和unittest
- Boost库学习(2)thread 1
- Boost库学习(3)thread 2
- Boost库学习(4)thread 3
- Boost库学习(6)filesystem
- Boost库学习(7)regex