Jiwu Bu

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  32 随笔 :: 0 文章 :: 25 评论 :: 0 Trackbacks
为了方便日常使用boost::filestream组件,将boost::filestream组件的基本封装。

/*
 * @file FileSystem.h
 * @brief Operation file or diretory
 * @author Jiwu Bu
 * @version 1.0.0
 * @date 2009-11-23
 
*/
#ifndef FILESYSTEM_H_H
#define FILESYSTEM_H_H

#include 
<iostream>
#include 
<vector>

using namespace std;

class CFileSystem
{
public:
    
/*
     * @brief Gets an array of dirctories from current direcoty,
     *        using Recur value to determine whether to search 
     *        subdirectories.
     * @param SubDirVec Ouput parameter, return the search result
     * @param DirPath
     * @param Recur  Whether search subdirectories.
     * 
     * @return 
     
*/
    
static bool GetDirectories(vector<string>& SubDirVec, 
        
const string& DirPath, bool Recur = false);

    
/*
     * @brief Get the names of files in the specified directory that 
     *        match the specified extensive name, using a value to 
     *        determine whether to search subdirectories.
     * 
     * @param FileVec Ouput parameter, return the search result
     * @param DirPath
     * @param ExeName Extensive name, if ExeName equal  "*.*"  search all file
     * @param Recur   Whether search subdirectories
     * 
     * @return 
     
*/
    
static bool GetFiles(vector<string>& FileVec, const string& DirPath, 
        
const string& ExeName, bool Recur = false);

    
/*
     * @brief Create a new directory.
     * 
     * @param Dir  New directory path. Example:/home/bujiwu/test
     * 
     * @return  true, if success
     *          false, if failed
     
*/
    
static bool CreateDirectory(const string & Dir);

    
/*
     * @brief Judge whether this file or diretory exists.
     * 
     * @param Path
     * 
     * @return  true, if exists
     *          false, if not exists
     
*/
    
static bool Exists(const string& Path);

    
/*
     * @brief Delete this file or directory
     * 
     * @param Path
     
*/
    
static void Delete(const string& Path);

    
/*
     * @brief Move file or directory from FromPath to ToPath.
     * 
     * @param FromPath
     * @param ToPath
     
*/
    
static void Move(const string& FromPath, const string& ToPath);

    
/*
     * @brief Copy file or directory from FromPath to ToPath.
     * 
     * @param FromPath
     * @param ToPath
     
*/
    
static void Copy(const string& FromPath, const string& ToPath);

    
/*
     * @brief Get file size
     * 
     * @param FilePath
     * 
     * @return 
     
*/
    
static unsigned long GetFileSize(const string& FilePath);
};

#endif

测试用例:
#include "../FileSystem/FileSystem.h"
#include 
<algorithm>
#include 
<iterator>
#include 
<string>

using namespace std;

int main(int argc, char* argv[])
{
    vector
<string> MyVec;

    
string Path = "/home/bujiwu/EncapDirectory";
    
    CFileSystem::Copy(
"/home/bujiwu/epoll", Path);

    CFileSystem::GetFiles(MyVec, Path, 
"*.*"true);

    copy(MyVec.begin(), MyVec.end(), ostream_iterator
<string>(cout , "\n") );

    
return 0;
}

http://www.cppblog.com/Files/bujiwu/FileSystem.rar

posted on 2009-11-23 13:44 bujiwu 阅读(784) 评论(0)  编辑 收藏 引用 所属分类: Boost

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