Chinaunix首页 | 论坛 | 博客
  • 博客访问: 55103
  • 博文数量: 21
  • 博客积分: 1440
  • 博客等级: 上尉
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-25 14:47
文章分类

全部博文(21)

文章存档

2010年(9)

2009年(12)

我的朋友

分类: C/C++

2009-09-02 18:08:43

  #include  
  #include  
  #include  
  #include  
  #include  
  #include
  
  void delete(char *filename)  
  {  
        if(unlink(filename)<0)  
        {   
            printf("delete file error\n");   
            exit(1);  
        }  
        else  
          printf("The file is deleted\n");  
     
        return; 
  }  
   
  int main(int argc,char **argv)  
  {  
        DIR   *dir;  
        struct   dirent *dirp;
        struct stat buf;  
       
        char   ch;  
        const   char*filename;  
        char   path[50]="/home/tem/";   
        char *option;   //选项   
    
        option=argv[1];  
        filename=argv[2];  
        if(!strcmp(option,"-i"))  
        {  
             printf("Are you sure delete the file? Y or N: ");   
            scanf("%c",&ch);   
             if(ch=='Y')   
             {   
               delete(filename);   
             }  
        }  
        else if(!strcmp(option,"-v"))  
        {  
            strncat(path,filename,strlen(filename)+1);  
            if(stat(path,&buf))  
            {   
               printf("stat() error\n");   
               exit(1);  
            }  
            else  
            {   
               printf("%s %d %d\n",buf->st_ino,
                buf->st_mode,buf->st_size);   
               delete(filename);  
            }  

          }
   
       return 0;   
  
  }  
 
 gcc delete.c -o del   
 ./del -v filename  

阅读(2585) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~