判断文件是否存在/返回文件大小

 std::string rawDataDir = CSystemHelper::GetRawDataDir();boost::filesystem::path pathRawDataDir(rawDataDir);bool ret = boost::filesystem::exists(pathRawDataDir);bool CSystemHelper::IsPathExist(const std::string& sPath){try{boost::filesystem::path path(sPath);return boost::filesystem::exists(path);}catch (...){return false;}}std::string CSystemHelper::GetParentPath(const std::string& fileFullPath){try{boost::filesystem::path fullPath = fileFullPath;return fullPath.parent_path().string();}catch (...){return "";}}uint64_t CSystemHelper::GetFileSize(const std::string& fileFullPath){using namespace boost::filesystem;uintmax_t size = 0u;boost::filesystem::path pathSource(fileFullPath);if (exists(pathSource)){boost::system::error_code error;try{size = file_size(pathSource, error);}catch(...){}}return static_cast<uint64_t>(size);}

(1) 创建文件夹

// 0:failed 1:succeed 2:existedint CSystemHelper::CreateDir(const string& dirPath){using namespace boost::filesystem;if (is_directory(dirPath))return 2;try{bool b = create_directories(path(dirPath));if(b)return 1;}catch (...){}return 0;}

(2)获取路径下的所有文件

void CSystemHelper::GetAllRawDataFileList(std::vector<std::string>& fileList,const std::string& dir){using namespace boost::filesystem;if (is_directory(dir)){directory_iterator end;directory_iterator pos(dir);for ( pos; pos != end; ++pos){if (!is_directory(*pos) && (extension(*pos) == ".raw"))fileList.push_back(pos->path().filename().string());}} }

(3)删除文件

bool CSystemHelper::DeleteFile(const std::string& fullPath){using namespace boost::filesystem;bool suc = false;path  ptest = fullPath;if(exists(fullPath)){try{suc = remove(ptest);}catch(...){suc = false;}}return suc;}

(4)删除整个文件夹

bool CSystemHelper::DeleteDir(const std::string& dir){using namespace boost::filesystem;bool suc = false;path ptest = dir;if (exists(ptest)){try{if(boost::filesystem::is_empty(ptest))suc = remove(ptest);else{uintmax_t num = remove_all(ptest);suc = (num != 0);}}catch(...){suc = false;}}return suc;}

(5)复制文件

 bool CSystemHelper::CopyTo(const std::string& sourfullpath, const std::string& targfullPath, bool overwrite){using namespace boost::filesystem;path targ = targfullPath;path sour = sourfullpath;bool suc = false;if (exists(sourfullpath) && ((!exists(targfullPath) || overwrite))){try{copy_file(sour, targ,copy_option::overwrite_if_exists);suc = true;}catch(...){//}}    return suc;}

复制文件夹

bool CSystemHelper::CopyDir(const std::string& sourDir, const std::string& destDir ){using namespace boost::filesystem;boost::filesystem::path PathSource(sourDir) ;boost::filesystem::path PathTarget(destDir) ;if( !exists(PathSource) )return false;if( !exists(PathTarget) )create_directories(PathTarget);directory_iterator end;bool suc = true;for( directory_iterator it(PathSource); it != end; ++it ){path newFrom = PathSource;newFrom /= it->path().filename().string();path newTo = PathTarget;newTo /= it->path().filename().string();if( is_directory( newFrom ) )suc = suc && CopyDir(newFrom.string(), newTo.string() );else {try{copy_file(newFrom, newTo,copy_option::overwrite_if_exists);}catch(...){suc = suc && false;}}}return suc;}

查找文件名相同后缀不同的所有文件

//查找文件名相同后缀不同的所有文件//dir:要查询的目录//fileName:查询的文件名//allFiles: 返回查询结果,带后缀文件名void CSystemHelper::find_files_with_name(const string& dir, const string& fileName, vector<string>& allFiles){try{if (!(exists(dir)) || !is_directory(dir)){return;}recursive_directory_iterator end;                  for (recursive_directory_iterator pos(dir) ;pos != end ; ++pos) //递归目录下的文件{string fileNameWithExpand = pos->path().filename().string();string subFileName = fileNameWithExpand.substr(0u, fileName.length());if (subFileName == fileName){allFiles.push_back(fileNameWithExpand);}}}catch (...){}}

filesystem操作相关推荐

  1. Hadoop API编程——FileSystem操作

    基于前面配置的HDFS伪分布式模式进行实验,完全分布式模式下次来搞.. 创建Java项目,File->New->Java Project,命名为TestHDFS 采用单元测试做实验,加入单 ...

  2. Tensorflow操作与函数全面解析

    转载自:http://blog.csdn.net/lenbow/article/details/52152766 1.tensorflow的基本运作 为了快速的熟悉TensorFlow编程,下面从一段 ...

  3. JAVA代码操作HDFS

    1.客户端环境准备 (1)将Hadoop-2.9.2安装包解压到非中文路径(例如:E:\hadoop-2.9.2) (2) 配置HADOOP_HOME环境变量 (3) 配置Path环境变量. (4)  ...

  4. Tensorflow一些常用基本概念与函数(二)

    1.tensorflow的基本运作 为了快速的熟悉TensorFlow编程,下面从一段简单的代码开始: import tensorflow as tf#定义'符号'变量,也称为占位符a = tf.pl ...

  5. 深入理解HDFS:Hadoop分布式文件系统

    深入理解HDFS:Hadoop分布式文件系统 文本详细介绍了HDFS中的许多概念,对于理解Hadoop分布式文件系统很有帮助. 1. 介绍 在现代的企业环境中,单机容量往往无法存储大量数据,需要跨机器 ...

  6. 【服务端渲染】之 Vue SSR

    前言 笔记来源:拉勾教育 大前端高薪训练营 阅读建议:内容较多,建议通过左侧导航栏进行阅读 Vue SSR 基本介绍 Vue SSR 是什么 官方文档:https://ssr.vuejs.org/ V ...

  7. 无法扩展该卷 因为群集的数量将超过文件系统_Ubifs文件系统分析

    转载是一种动力 分享是一种美德 1.  引言 UBIFS,Unsorted Block Image File System,无排序区块图像文件系统.它是用于固态硬盘存储设备上,并与LogFS相互竞争, ...

  8. Tensorflow常用函数汇总

    转载自:http://blog.csdn.net/lenbow/article/details/52152766 1.tensorflow的基本运作 为了快速的熟悉TensorFlow编程,下面从一段 ...

  9. Tensorflow的基本概念与常用函数

    Tensorflow一些常用基本概念与函数(一) 1.tensorflow的基本运作 为了快速的熟悉TensorFlow编程,下面从一段简单的代码开始: import tensorflow as tf ...

最新文章

  1. 懂语言者得天下:NLP凭什么被称为人工智能的掌上明珠?
  2. R语言效用分析 ( 效能分析、Power analysis)、除了pwr包之外还有其它包、例如、基因研究中的效能分析、MBESS包可用于各种形式的效能分析和最少样本量确定、其他效用分析包的简要介绍
  3. python 少儿趣味编程下载_趣味儿童编程软件(scratch)
  4. [Google Guava] 1.2-前置条件
  5. JAVA数据库连接的另一种实现及简单的数据插入及显示
  6. python将object转换为float_将pandas系列类型从object转换为float64
  7. 科学计算机怎么算坐标,用科学计算器fx-5800算坐标怎么按
  8. ExtJS 中自定义类
  9. Linux系统文件类型 特殊文件 和 进程间通信机制
  10. memory php 变量,php入门-变量
  11. mysql求和语句大全_sql查询语句大全
  12. 织梦文章页模板使用php语法,织梦文章页面模板顶一下踩一下调用教程
  13. 游戏开发之C++IO流(C++基础)
  14. 终于有人把流量运营讲明白了
  15. 【软件测试】数据库大厂面试真题解析(二叉树算法纯干货!)
  16. 双屏 3840 * 1080 如何装逼?不同的屏幕显示不同的壁纸。php 定时脚本下载必应每日壁纸。
  17. 本体创始人李俊:公链和跨界是未来区块链发展的关键(GBCAX)
  18. MySQL、SQL Server、Hive对时间格式化
  19. 一个小小黑点乱了我的芳心
  20. android中如何找到数据库文件

热门文章

  1. SVN update时出现:E155004错误
  2. 基于树梅派4B的建立个人网站
  3. Tushare学习文档(七 龙虎榜数据)
  4. 老师给我的指点——深刻剖析了我
  5. css 左箭头右箭头
  6. postfix+cyrus-sasl+extmail+dovecot基于MySQL认证的邮件系统
  7. 执行RMAN恢复的高级场景_通过网络还原和恢复文件
  8. Apollo:Routing模块
  9. 推荐一波实用资源网站
  10. 【DPDK】DPDK技术介绍--研读