zoukankan      html  css  js  c++  java
  • 采用Boost::filesystem操作文件

    // BoostTest.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include "boost/filesystem.hpp"   // includes all needed Boost.Filesystem declarations
    #include <iostream>               // for std::cout
    using namespace boost::filesystem; 
    using namespace std;
    
    
    #include <boost/filesystem.hpp>
    #include <vector>
    #include <string>
    #include <iostream>
    
    namespace fs = boost::filesystem;
    
    void getAllFileOfPath(std::string strPath,std::vector<std::string>& dllNames)
    {
    
    
    	fs::path fullPath(fs::initial_path());        // 初始化为本项目路径
    	fullPath = fs::system_complete(fs::path(strPath,fs::native));    //将相对路径转换为绝对路径
    
    	// 注:fullPath 使用相对路径、绝对路径都可行
    
    	if (!fs::exists(fullPath))            //路径是否存在
    	{
    		std::cout << "找不到指定目录,请检查该目录是否存在:";
    		std::cout << fullPath.native_file_string() << std::endl;        // 输出路径名
    		return;
    	}
    	if (!fs::is_directory(fullPath))        // 是否是目录
    	{
    		std::cout << "指定路径不是目录";
    		std::cout << fullPath.native_file_string() << std::endl;
    		return;
    	}
    
    	fs::directory_iterator end_iter;
    	for (fs::directory_iterator file_itr(fullPath); file_itr != end_iter; ++file_itr)
    	{
    		if (!fs::is_directory(*file_itr) && (fs::extension(*file_itr)!=".exe"))        // 文件后缀
    		{
    			dllNames.push_back(file_itr->leaf());    //获取文件名
    		}
    	}
    
    
    }
    
    
    int main() 
    {
    	try
    	{
    		string p("C:/TDDOWNLOAD/说岳全传/说岳全传/fdsaf");
    		std::vector<std::string> dllNames;
    		getAllFileOfPath(p,dllNames);
    
    		std::vector<std::string>::iterator itr = dllNames.begin();
    		for (;itr != dllNames.end(); ++itr)
    		{
    			std::cout<<*itr<<std::endl;
    			remove(p+"/"+*itr);
    		}
    	}
    	catch (exception &e)
    	{
    		cout<<e.what()<<endl;
    	}
    }
    
    
  • 相关阅读:
    基于索引的MySQL优化
    SQL优化:
    in的对象选择(子查询还是List集合),in 的优化,in与exists
    嵌套查询及其作用域:
    group by实现原理及其作用
    批量打回未报bug修复
    解析Job,bpmn文件的小项目总结
    用户短时间内多次提交与保存带来的问题
    嵌套连接
    多范围读取优化
  • 原文地址:https://www.cnblogs.com/lilun/p/1813023.html
Copyright © 2011-2022 走看看