青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 224  文章 - 41  trackbacks - 0
<2012年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

享受編程

常用鏈接

留言簿(11)

隨筆分類(159)

隨筆檔案(224)

文章分類(2)

文章檔案(4)

經典c++博客

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

原文地址:http://blog.csdn.net/zhangzuohai/archive/2009/06/19/4282117.aspx
遍歷所有的文件和文件夾并對文件進行操作。

#include "stdlib.h"   #include "direct.h"   #include "string.h"   #include "io.h"   #include "stdio.h"    #include "iostream.h"     class CBrowseDir   {   protected:       //存放初始目錄的絕對路徑,以'\'結尾       char m_szInitDir[_MAX_PATH];          public:       //缺省構造器       CBrowseDir();              //設置初始目錄為dir,如果返回false,表示目錄不可用       bool SetInitDir(const char *dir);              //開始遍歷初始目錄及其子目錄下由filespec指定類型的文件       //filespec可以使用通配符 * ?,不能包含路徑。       //如果返回false,表示遍歷過程被用戶中止       bool BeginBrowse(const char *filespec);          protected:       //遍歷目錄dir下由filespec指定的文件       //對于子目錄,采用迭代的方法       //如果返回false,表示中止遍歷文件       bool BrowseDir(const char *dir,const char *filespec);              //函數BrowseDir每找到一個文件,就調用ProcessFile       //并把文件名作為參數傳遞過去       //如果返回false,表示中止遍歷文件       //用戶可以覆寫該函數,加入自己的處理代碼       virtual bool ProcessFile(const char *filename);              //函數BrowseDir每進入一個目錄,就調用ProcessDir       //并把正在處理的目錄名及上一級目錄名作為參數傳遞過去       //如果正在處理的是初始目錄,則parentdir=NULL       //用戶可以覆寫該函數,加入自己的處理代碼       //比如用戶可以在這里統計子目錄的個數       virtual void ProcessDir(const char *currentdir,const char *parentdir);   };     CBrowseDir::CBrowseDir()   {       //用當前目錄初始化m_szInitDir       getcwd(m_szInitDir,_MAX_PATH);              //如果目錄的最后一個字母不是'\',則在最后加上一個'\'       int len=strlen(m_szInitDir);       if (m_szInitDir[len-1] != '\\')           strcat(m_szInitDir,"\\");   }     bool CBrowseDir::SetInitDir(const char *dir)   {       //先把dir轉換為絕對路徑       if (_fullpath(m_szInitDir,dir,_MAX_PATH) == NULL)           return false;              //判斷目錄是否存在       if (_chdir(m_szInitDir) != 0)           return false;              //如果目錄的最后一個字母不是'\',則在最后加上一個'\'       int len=strlen(m_szInitDir);       if (m_szInitDir[len-1] != '\\')           strcat(m_szInitDir,"\\");              return true;   }     bool CBrowseDir::BeginBrowse(const char *filespec)   {       ProcessDir(m_szInitDir,NULL);       return BrowseDir(m_szInitDir,filespec);   }     bool CBrowseDir::BrowseDir(const char *dir,const char *filespec)   {       _chdir(dir);              //首先查找dir中符合要求的文件       long hFile;       _finddata_t fileinfo;       if ((hFile=_findfirst(filespec,&fileinfo)) != -1)       {           do          {               //檢查是不是目錄               //如果不是,則進行處理               if (!(fileinfo.attrib & _A_SUBDIR))               {                   char filename[_MAX_PATH];                   strcpy(filename,dir);                   strcat(filename,fileinfo.name);                   cout << filename << endl;                   if (!ProcessFile(filename))                       return false;               }           } while (_findnext(hFile,&fileinfo) == 0);           _findclose(hFile);       }       //查找dir中的子目錄       //因為在處理dir中的文件時,派生類的ProcessFile有可能改變了       //當前目錄,因此還要重新設置當前目錄為dir。       //執行過_findfirst后,可能系統記錄下了相關信息,因此改變目錄       //對_findnext沒有影響。       _chdir(dir);       if ((hFile=_findfirst("*.*",&fileinfo)) != -1)       {           do          {               //檢查是不是目錄               //如果是,再檢查是不是 . 或 ..                //如果不是,進行迭代               if ((fileinfo.attrib & _A_SUBDIR))               {                   if (strcmp(fileinfo.name,".") != 0 && strcmp                       (fileinfo.name,"..") != 0)                   {                       char subdir[_MAX_PATH];                       strcpy(subdir,dir);                       strcat(subdir,fileinfo.name);                       strcat(subdir,"\\");                       ProcessDir(subdir,dir);                       if (!BrowseDir(subdir,filespec))                           return false;                   }               }           } while (_findnext(hFile,&fileinfo) == 0);           _findclose(hFile);       }       return true;   }     bool CBrowseDir::ProcessFile(const char *filename)   {       return true;   }     void CBrowseDir::ProcessDir(const char                                *currentdir,const char *parentdir)   {   }     //從CBrowseDir派生出的子類,用來統計目錄中的文件及子目錄個數   class CStatDir:public CBrowseDir   {   protected:       int m_nFileCount;   //保存文件個數       int m_nSubdirCount; //保存子目錄個數          public:       //缺省構造器       CStatDir()       {           //初始化數據成員m_nFileCount和m_nSubdirCount           m_nFileCount=m_nSubdirCount=0;       }              //返回文件個數       int GetFileCount()       {           return m_nFileCount;       }              //返回子目錄個數       int GetSubdirCount()       {           //因為進入初始目錄時,也會調用函數ProcessDir,           //所以減1后才是真正的子目錄個數。           return m_nSubdirCount-1;       }          protected:       //覆寫虛函數ProcessFile,每調用一次,文件個數加1       virtual bool ProcessFile(const char *filename)       {           m_nFileCount++;           return CBrowseDir::ProcessFile(filename);       }              //覆寫虛函數ProcessDir,每調用一次,子目錄個數加1       virtual void ProcessDir           (const char *currentdir,const char *parentdir)       {           m_nSubdirCount++;           CBrowseDir::ProcessDir(currentdir,parentdir);       }   };     void main()   {       //獲取目錄名       char buf[256];       printf("請輸入要統計的目錄名:");       gets(buf);              //構造類對象       CStatDir statdir;              //設置要遍歷的目錄       if (!statdir.SetInitDir(buf))       {           puts("目錄不存在。");           return;       }              //開始遍歷       statdir.BeginBrowse("*.*");       printf("文件總數: %d\n子目錄總數:%d\n",statdir.GetFileCount(),statdir.GetSubdirCount());   }   

本文來自CSDN博客,轉載請標明出處:http:
//blog.csdn.net/zhangzuohai/archive/2009/06/19/4282117.aspx

相關函數的解釋
--------------------------------------------------------------------------------
_fullpath(char*abspath,char* relpath,size_t maxsize);
參數解釋

absPath
Pointer to a buffer containing the absolute or full path name, or NULL.

relPath
Relative path name.

maxLength
Maximum length of the absolute path name buffer (absPath ). This length is in bytes for _fullpath but in wide characters (wchar_t ) for _wfullpath .

返回值
Each of these functions returns a pointer to a buffer containing the absolute path name (absPath ). If there is an error (for example, if the value passed in relPath includes a drive letter that is not valid or cannot be found, or if the length of the created absolute path name (absPath ) is greater than maxLength ), the function returns NULL .

  Remarks

The _fullpath function expands the relative path name in relPath to its fully qualified or absolute path and stores this name in absPath . If absPath is NULL, malloc is used to allocate a buffer of sufficient length to hold the path name. It is the responsibility of the caller to free this buffer. A relative path name specifies a path to another location from the current location (such as the current working directory: "."). An absolute path name is the expansion of a relative path name that states the entire path required to reach the desired location from the root of the file system. Unlike _makepath , _fullpath can be used to obtain the absolute path name for relative paths (relPath ) that include "./" or "../" in their names.

For example, to use C run-time routines, the application must include the header files that contain the declarations for the routines. Each header file include statement references the location of the file in a relative manner (from the application's working directory):

--------------------------------------------------------------------------------
改變當前的工作目錄到指定的目錄中
_chdir, _wchdir
Changes the current working directory.

int _chdir(
   const char *dirname
);
int _wchdir(
   const wchar_t *dirname
);Parameters
dirname
Path of new working directory.

  Return Value
These functions return a value of 0 if successful. A return value of –1 indicates failure. If the specified path could not be found, errno is set to ENOENT . If dirname is NULL, the invalid parameter handler is invoked, as described in Parameter Validation . If execution is allowed to continue, errno is set to EINVAL and the function returns -1.

  Remarks

The _chdir function changes the current working directory to the directory specified by dirname . The dirname parameter must refer to an existing directory. This function can change the current working directory on any drive. If a new drive letter is specified in dirname , the default drive letter is changed as well. For example, if A is the default drive letter and \BIN is the current working directory, the following call changes the current working directory for drive C and establishes C as the new default drive:

代碼

posted on 2009-12-13 14:40 漂漂 閱讀(1096) 評論(0)  編輯 收藏 引用

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            一区二区高清视频| 欧美成人有码| 欧美日韩一区二区视频在线观看| 欧美亚洲系列| 亚洲欧美成人网| 欧美一区二区三区的| 欧美一区国产一区| 老司机精品视频网站| 免费在线视频一区| 欧美日韩在线不卡一区| 国产精品人人爽人人做我的可爱| 国产乱人伦精品一区二区| 国产欧美在线观看一区| 国产在线精品自拍| 亚洲国产天堂久久国产91| 妖精成人www高清在线观看| 日韩视频在线一区二区三区| 亚洲一区中文| 久热成人在线视频| 日韩一级视频免费观看在线| 欧美一区二区三区视频免费播放| 亚洲国产毛片完整版| 亚洲第一狼人社区| 影音先锋日韩有码| 亚洲性人人天天夜夜摸| 久久九九热re6这里有精品| 亚洲国产精品99久久久久久久久| 欧美国产视频在线观看| 一区二区三区视频在线观看 | 亚洲国产岛国毛片在线| 一区二区三区日韩| 久久免费高清| 国产精品女人毛片| 亚洲日本欧美天堂| 久久久久在线| 亚洲香蕉视频| 欧美精品 国产精品| 国产亚洲欧美一区在线观看| 一区二区日韩伦理片| 老司机免费视频一区二区| av成人免费观看| 欧美77777| 狠狠久久亚洲欧美| 久久成人免费视频| 亚洲午夜电影网| 欧美日韩国产在线播放| 在线观看一区| 久久久之久亚州精品露出| 亚洲午夜视频在线| 久久精品五月| 亚洲欧美另类国产| 欧美日韩伦理在线免费| 亚洲精品乱码久久久久| 久久精品理论片| 亚洲男人天堂2024| 国产精品永久在线| 性欧美暴力猛交69hd| 99精品视频一区二区三区| 欧美极品一区| 亚洲视频 欧洲视频| 亚洲免费观看高清完整版在线观看熊 | 久久伊人精品天天| 精品51国产黑色丝袜高跟鞋| 欧美一区二区三区喷汁尤物| 亚洲一区视频在线观看视频| 欧美日韩一区三区四区| 亚洲一区二区综合| 亚洲影视九九影院在线观看| 国产精品视频网址| 久久久久久久网站| 久久综合中文字幕| 亚洲精品在线电影| 久久精品理论片| 亚洲欧美日韩精品| 亚洲一区二区三区四区五区午夜| 欧美日韩精品免费看| 一区二区三区国产在线观看| 亚洲精品在线免费观看视频| 欧美日韩中文字幕在线| 亚洲欧美日韩国产综合在线 | 亚洲激情专区| 亚洲精品中文字幕女同| 国产精品久久久| 久久久久九九九九| 欧美88av| 亚洲综合欧美日韩| 欧美亚洲综合在线| 亚洲激情视频网站| 亚洲国产视频一区二区| 欧美高清视频在线| 欧美日韩一区三区四区| 久久九九国产| 欧美精品二区三区四区免费看视频| 亚洲综合色噜噜狠狠| 久久精品最新地址| av成人国产| 欧美一区午夜精品| 99国产精品久久久久久久| 亚洲欧美日韩另类| 亚洲美女性视频| 欧美一区二区大片| 99这里只有久久精品视频| 欧美中在线观看| 亚洲一区二区3| 久久精品在这里| 亚洲男人影院| 欧美国产在线观看| 久久免费视频网站| 国产精品国产自产拍高清av王其| 玖玖综合伊人| 国产精品久久国产精品99gif| 欧美成人精品激情在线观看| 国产精品亚洲激情| 亚洲欧洲在线播放| 极品裸体白嫩激情啪啪国产精品| 国产精品99久久久久久人| 亚洲三级观看| 久久综合影视| 美日韩精品免费| 国产视频自拍一区| 亚洲女优在线| 性伦欧美刺激片在线观看| 欧美色中文字幕| 亚洲精品在线电影| 日韩视频久久| 欧美黑人多人双交| 亚洲国产老妈| 亚洲人体1000| 欧美不卡福利| 亚洲国产精品成人久久综合一区| 亚洲福利免费| 免费不卡欧美自拍视频| 欧美黄色一级视频| 亚洲国产欧美一区二区三区同亚洲 | 樱花yy私人影院亚洲| 亚洲一区二区综合| 亚洲欧美日韩在线| 欧美午夜电影在线| 亚洲精品中文在线| 亚洲午夜久久久久久久久电影院 | 亚洲网址在线| 亚洲欧美日韩视频二区| 欧美三级视频| 亚洲一区二区三区在线| 香蕉视频成人在线观看| 国产女人精品视频| 久久国产黑丝| 欧美大片免费| 99re6热只有精品免费观看| 欧美喷潮久久久xxxxx| 亚洲美女中文字幕| 亚洲伊人一本大道中文字幕| 国产精品乱子乱xxxx| 性欧美大战久久久久久久久| 久久免费黄色| 亚洲精品黄色| 国产精品久久影院| 久久精品国产久精国产一老狼| 欧美69视频| 正在播放欧美一区| 国产欧美在线观看| 美女精品在线| 一本色道久久综合狠狠躁的推荐| 亚洲女同在线| 影音先锋日韩精品| 欧美日韩福利在线观看| 午夜亚洲视频| 亚洲精品一区二区三区不| 午夜久久黄色| 91久久夜色精品国产九色| 欧美三级精品| 一本一本久久a久久精品综合麻豆| 国产精品高清网站| 久久久噜噜噜| 洋洋av久久久久久久一区| 久久国产一区二区| 日韩视频久久| 精品成人乱色一区二区| 欧美日韩在线播放三区四区| 久久久久se| 亚洲一区二区欧美日韩| 欧美国产精品人人做人人爱| 欧美亚洲尤物久久| 亚洲精品日韩一| 狠狠色伊人亚洲综合成人| 欧美日韩一本到| 老司机午夜精品| 欧美亚洲一区| 在线亚洲电影| 亚洲激情电影在线| 久久免费国产精品| 欧美在线播放高清精品| 一区二区三区日韩精品| 亚洲高清视频一区二区| 国产一区二区电影在线观看 | 久久久亚洲国产天美传媒修理工| 亚洲性图久久| 久久综合图片| 这里只有精品丝袜| 亚洲黄网站在线观看|