#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
阅读(2629) | 评论(0) | 转发(0) |