请看代码(程序运行后没效果):unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
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);
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;procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
Drive: PChar;
begin
for I := 0 to 31 do
begin
if Boolean(GetLogicalDrives and (1 SHL I)) then
begin
Drive:= PChar(CHR(65 + I) + ':\');
getTree(Drive);
end;
end;
end;end.
出现如下问题:
[Warning] Unit1.pas(55): Symbol 'FileSetAttr' is specific to a platform
[Warning] Unit1.pas(55): Symbol 'faArchive' is specific to a platform
以上代码想解决的问题:
我中了一个恶意软件,它会生成许多以“an2b”为后缀名的文件占用硬盘空间,且生成文件的属性为“隐藏”、“只读”、 “存档”三者并存(有的只有一个或两个,而不是三者并存),请问在不更改文件属性、注册表、系统设置等情况下,如何将整个硬盘均搜索一遍并把找到的这些生成的文件删除?(希望编程时不添加任何控件,打开程序即自动进行,不需人工干预)谢谢。希望给出完整的详细的代码(从开始到结尾)以及详细的注析。(不要是控制台程序)
我是新手。多谢!(100分赠送!)
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
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);
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;procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
Drive: PChar;
begin
for I := 0 to 31 do
begin
if Boolean(GetLogicalDrives and (1 SHL I)) then
begin
Drive:= PChar(CHR(65 + I) + ':\');
getTree(Drive);
end;
end;
end;end.
出现如下问题:
[Warning] Unit1.pas(55): Symbol 'FileSetAttr' is specific to a platform
[Warning] Unit1.pas(55): Symbol 'faArchive' is specific to a platform
以上代码想解决的问题:
我中了一个恶意软件,它会生成许多以“an2b”为后缀名的文件占用硬盘空间,且生成文件的属性为“隐藏”、“只读”、 “存档”三者并存(有的只有一个或两个,而不是三者并存),请问在不更改文件属性、注册表、系统设置等情况下,如何将整个硬盘均搜索一遍并把找到的这些生成的文件删除?(希望编程时不添加任何控件,打开程序即自动进行,不需人工干预)谢谢。希望给出完整的详细的代码(从开始到结尾)以及详细的注析。(不要是控制台程序)
我是新手。多谢!(100分赠送!)
解决方案 »
- 这段代码是完全正确的 就想问
- 多表关联查询问题
- 菜鸟请教:如果客户端必须等待seversocket返回结果后才可以做下一步的操作是否应该选择stThreadBlocking方式?
- 真想离开delphi(个人的感觉)
- 为什么老是出错呢??!!晕啊!adoquery问题
- 寻找压缩控件!
- 空格
- 不分大小写模糊查找memo型字段,有什么好办法?
- 问题:当listbox2中有如下数据时.................//瑶瑶
- 怎样在windos的DOS命令行下编译delphi的工程文件
- 如何得到scrollbar的横竖那个移动滑块的移动距离!!请求各位大侠告诉我答案!!
- 求教,有关FEM的数值计算(2D)
var attr : integer; filename : string; begin filename := 'myfile'; attr := FileGetAttr(filename); end; 3. 设置文件属性(如设置归档属性 -> faArchive )
attr := attr or faArchive; //如要去掉某一属性,则如下句 attr := attr and (not faArchive); //保留其它属性 if FileSetAttr(filename, attr)=0 then //成功代码 else //失败代码 4. 附文件属性常量
Constant Value Description
faReadOnly $00000001 Read-only files 只读文件
faHidden $00000002 Hidden files 隐藏文件
faSysFile $00000004 System files 系统文件
faVolumeID $00000008 Volume ID files 卷标文件
faDirectory $00000010 Directory files 目录
faArchive $00000020 Archive files 归档文件
faAnyFile $0000003F Any file 任意文件
请看看这个,再改一下上面的