C++学习

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  3 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks

常用链接

留言簿

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

#pragma once
#ifndef get_all_dll_file_of_path_h
#define get_all_dll_file_of_path_h

#include 
<boost/filesystem.hpp>
#include 
<vector>
#include 
<string>
#include 
<iostream>

namespace fs = boost::filesystem;

void getAllFileOfPath(std::vector<std::string>& dllNames)
{

    std::
string strPath = "../debug/"/*"f:\\c++\\study\\debug\\"*/;

    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)==".dll"))        // 文件后缀
        {
            dllNames.push_back(file_itr
->leaf());    //获取文件名
        }

    }


    std::vector
<std::string>::iterator itr = dllNames.begin();
    
for (;itr != dllNames.end(); ++itr)
    
{
        std::cout
<<*itr<<std::endl;
    }

}


#endif //get_all_dll_file_of_path_h
posted on 2009-09-18 11:13 holyhw 阅读(2676) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理