“搜索”磁盘,并在各盘根目录下建立一个垃圾文件
/*Name: “搜索”磁盘,并在各盘根目录下建立一个垃圾文件
Copyright:
Author: 随心
Date: 30-09-07 21:24
Description: “搜索”磁盘,并在各盘根目录下建立一个垃圾文件search_rubbish,之后在C盘根目录下
生成一个删除垃圾文件的batch file,双击运行即可删除生成的所有垃圾文件以及del.bat。
*/
#include <stdio.h>
#include <stdlib.h>
#define TRY_MAX 10 //尝试的最大次数
void search_drive(void)
{
FILE *search,*del;
char path[20],drive_symbol='c',*self_destruction="del c:\\del.bat",
*echo="@echo off\n";
int n=0;
if((del=fopen("c:\\del.bat","wt"))!=NULL)//注意del前的的整体括号不能少
{
fprintf(del,"%s",echo);
fclose(del);
}
else
printf("create the batch file unsuccessfully!\n");
while(1)
{
sprintf(path,"%c:\\search_rubbish",drive_symbol); //这里的“\\“不能少,否则会出现意外
if((search=fopen(path,"w"))!=NULL&&(del=fopen("c:\\del.bat","at+"))!=NULL)
{
fprintf(search,"%s",path);
fprintf(del,"del %s\n",path);
drive_symbol++;
fclose(search);
fclose(del);
}
else
{
drive_symbol++;//如果打开失败,则尝试下一个盘符
n++;
if(n==TRY_MAX)
break;
continue;
}
}
if((del=fopen("c:\\del.bat","at+"))!=NULL)
fprintf(del,"%s",self_destruction);
fclose(del);
}
int main(void)
{
search_drive();
//system("c:\\del.bat"); //自动删除生成的所有文件
return 0;
}