我中了一个恶意软件,它会生成许多以“an2b”为后缀名的文件占用硬盘空间,且生成文件的属性为“隐藏”、“只读”、“存档”三者并存(有的只有一个或两个,而不是三者并存),请问在不更改文件属性、注册表、系统设置等情况下,如何将整个硬盘均搜索一遍并把找到的这些生成的文件删除?(希望编程时不添加任何控件,打开程序即自动进行,不需人工干预)谢谢。希望给出完整的详细的代码(从开始到结尾)以及详细的注析。(不要是控制台程序)
我是新手。多谢!

解决方案 »

  1.   

    function   JudgeDir(Attr:integer):boolean;
     var
         i:integer;
      begin
         i:=Attr;   if   i>=32   then   i:=i-32;   //排除文档文件   
          if   i>=16   
              then   Result:=true   
              else   Result:=false;   //返回是否是目录   
      end;     function  getTree(Dir:string):integer;
      var   
          Sr:TSearchRec;   Err,ErrorFile,i:integer;   
         cc, CurFilePath,TempFilePath:string;  begin   
          ErrorFile:=0;  
          CurFilePath:=Dir;   TempFilePath:=CurFilePath;     
          Err:=FindFirst(Dir+'\*.*',$37,Sr);    
          while   (Err   =   0)   do   
              begin   
                  if   Sr.Name[1]<>'.'   
                      then   begin   
                          if   JudgeDir(Sr.Attr)
                              then   begin    
                                  TempFilePath:=CurFilePath;
                                 //保存当前目录
                                  CurFilePath:=CurFilePath+'\'+Sr.Name;
                                  if ExtractFileExt(sr.Name)='.an2b' then
                                  begin
                                  FileSetAttr(sr.Name,faArchive+faAnyFile);
                                  deletefile(sr.Name);
                                  form1.memo1.Lines.Add('发现垃圾文件'+sr.name+'且已清除!');
                                    end;
                                  i:=getTree(CurFilePath);   //递归调用   
                                  if   i<>0   then   ErrorFile:=ErrorFile+i-1;
                                  ChDir('..');   //返回上一级目录   
                              
                                  CurFilePath:=TempFilePath;   //恢复当前目录
                              end
                              else   begin   //处理文件情况
                               cc:=curfilepath+'\'+sr.Name;                         
                              end;   
                      end;   
                  Err:=FindNext(Sr);   
              end;
     //     ChDir('..');   
        
          //处理无法删除总目录   
          Result:=ErrorFile;  
      end;   调用例子:
    getTree('c:\');