• <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>
            posts - 297,  comments - 15,  trackbacks - 0
            //功能函數,遞歸遍歷指定目錄。
            void printdir(char *dir, int depth)
            {
                DIR *dp;
                struct dirent *entry;
                struct stat statbuf;

                //打開指定目錄建立目錄流
                if ((dp = opendir(dir)) == NULL) {
                   fprintf(stderr, "Can't open directory: %s\n", dir);
                   return;
                }
                chdir(dir);   //切換目錄
                while((entry = readdir(dp)) != NULL) {
                   lstat(entry->d_name, &statbuf);
                   if (S_ISDIR(statbuf.st_mode)) {
                      /* Found a directory, but ignore . and .. */
                      if (strcmp(".", entry->d_name) == 0 || 
                         strcmp("..", entry->d_name) == 0)
                         continue;
                      printf("%*s%s/\n", depth, " ", entry->d_name);
                      /* Recurse at a new indent level */
                      printdir(entry->d_name, depty+4);
                   }
                   else
                      printf("%*s%s\n", depth, " ", entry->d_name);
                }
                chdir("..");
                closedir(dp);
            }

            //main函數
            int main(int argc, char *argv[])
            {
                char *topdir = ".";
                if (argc >= 2)
                   topdir = argv[1];

                printf("Directory scan of %s\n", topdir);
                printdir(topdir, 0);
                printf("done.\n");

                exit(0);
            }

            PS.程序實現遞歸遍歷指定的目錄內容
            若目標程序名為"printdir",則可通過以下命令運行:
            $ printdir /usr/local | more
            輸出結果將分頁顯示。
            我們可以此為基礎,對之進行有效擴充,以實現更強大實用且通用
            的程序。
            posted on 2010-01-05 20:21 chatler 閱讀(477) 評論(0)  編輯 收藏 引用
            <2009年11月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            常用鏈接

            留言簿(10)

            隨筆分類(307)

            隨筆檔案(297)

            algorithm

            Books_Free_Online

            C++

            database

            Linux

            Linux shell

            linux socket

            misce

            • cloudward
            • 感覺這個博客還是不錯,雖然做的東西和我不大相關,覺得看看還是有好處的

            network

            OSS

            • Google Android
            • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
            • os161 file list

            overall

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            欧美综合天天夜夜久久| 日韩欧美亚洲国产精品字幕久久久| 91久久香蕉国产熟女线看| 成人免费网站久久久| 国产精品免费看久久久| 国内精品人妻无码久久久影院| 久久亚洲中文字幕精品一区| 久久精品国产亚洲AV久| 婷婷久久香蕉五月综合加勒比| 久久综合香蕉国产蜜臀AV| 久久精品国产精品青草| 国产高清国内精品福利99久久| 亚洲欧洲久久久精品| 精品国产乱码久久久久软件| 亚洲精品国产自在久久| 国内精品伊人久久久久妇| 97超级碰碰碰久久久久| 99久久超碰中文字幕伊人| 91精品国产91久久| 久久久久99精品成人片| 精品无码久久久久国产| 亚洲国产精品婷婷久久| 久久久免费观成人影院| 最新久久免费视频| 久久国产乱子伦免费精品| 久久人人爽人人人人片av| 久久国产精品99国产精| 狠狠人妻久久久久久综合蜜桃| 久久99精品国产自在现线小黄鸭| 青青青伊人色综合久久| 久久无码AV中文出轨人妻| 久久精品国产亚洲AV高清热| 久久精品成人免费观看97| 亚洲欧美日韩中文久久| 国产69精品久久久久99| 亚洲国产精品成人久久| 久久久久亚洲AV成人网人人网站| 久久久老熟女一区二区三区| 婷婷久久综合九色综合九七| 99久久精品日本一区二区免费 | 久久精品成人免费国产片小草|