• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 怎么刪除一個非空的目錄?

    發表于:2007-05-25來源:作者:點擊數: 標簽:空的這是怎么刪除目錄
    這是還沒寫好的源碼: #include stdio.h#include stdlib.h#include dirent.h#include unistd.h#include sys/types.hint main( void ){ DIR* dirp; struct dirent* direntp; struct stat buf; pid_t pid; dirp = opendir( /share/tmp );/*打開一個目錄 */ if(

    這是還沒寫好的源碼:

    #include <stdio.h>
    #include <stdlib.h>
    #include <dirent.h>
    #include <unistd.h>
    #include <sys/types.h>
    int main( void )
    {
        DIR* dirp;
        struct dirent* direntp;
        struct stat    buf;
        pid_t          pid;
        dirp = opendir( "/share/tmp" );/*打開一個目錄 */
        if( dirp == NULL ) {
                 perror( "can't open /share/tmp" );
        } else {
            for( ; ; ) {
                  direntp = readdir( dirp ); /*讀目錄里的內容*/
                  if( direntp == NULL ) /*如果是個空目錄就把它刪除*/
                          rmdir(/share/tmp);
                  for( ; ; ) {
                          if(lstat(directp->s_name,&buf)<0) { /*讀出文件名*/
                                 printf("lstat error\n");
                                 exit(-1);
                          }else{
                                 if( ! S_ISDIR(buf.st_mode)) < 0) { /*判斷是否是一個目錄*/
                                         printf("check file mode error\n");
                                         exit(1);
                                 }else if
                                         unlink(directp->s_name) ; /*如果不是就刪除它*/
                                 else
                                         if((pid=fork())<0) {/*如果是就判斷是否是一個空目錄,是就刪除它,這里考慮得不周到,fork一個進程,運行上面的算法,就是這里不懂了。要寫個函數吧?*/
                                                   printf("fork error\n");
                                                   exit(1);
                                         else if(pie == 0 )
                                                   chdir(directp->s_name);/*新的進程cd到新的目錄*/
     
                               
     
     
            }
            closedir( dirp );
        }
        return EXIT_SUCCESS;
    }

     }
            closedir( dirp );
        }
        return EXIT_SUCCESS;
    }

    你沒有考慮'.'和'..'

    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>