如果遍历PE文件呀
我想:
遍历除系统盘外的所有EXE文件,然后在过滤大小在5M以上的,然后在过滤检查剩下的是不是PE文件(PE文件的前俩字节是MZ,其实不要着步也可以,尽量提供把),
然后把所有剩下的用MEMO显示出来
比如
d:\1.exe
d:\2.exe
让代码尽量简短.
我想:
遍历除系统盘外的所有EXE文件,然后在过滤大小在5M以上的,然后在过滤检查剩下的是不是PE文件(PE文件的前俩字节是MZ,其实不要着步也可以,尽量提供把),
然后把所有剩下的用MEMO显示出来
比如
d:\1.exe
d:\2.exe
让代码尽量简短.
解决方案 »
- bcb版没有解决的问题,跑delphi来问问,100分,各位专家请进
- Sockets问题?
- 高手请进!!关于ClientSocket的问题~~~~
- Help Me~~
- 我的问题都一个星期了,还是没人回答,帮帮我!!!
- 那位大侠有数据库报表打印的基础教程(急)
- Insert into b (id,name) values(pno,pname)运行错误
- 初学Delphi,请教关于soap/web service客户端调用perl服务端的问题。
- 谁知道怎么样在批处理命令中自动删除文件!!!!???
- 在win2000下,当用户注销时,发送的消息是什么,在98下是WM_USERCHANGED,,
- delphi基于API 控制视频采集卡视频亮度,对比度怎么设置?请高手帮帮忙,最好有代码,谢谢 。
- 貌似用createProcess打开网页后,返回的子进程PID在一次执行结束后会被系统自动提升,变成跟父进程同级的进程
dwDrivers: LongWord;
I: Integer;
sysDir: AnsiString;
strDriver,strCurrentDir: AnsiString; FindFileData: TWIN32FindData;
hFindHandle: THandle; dirList: TStringList;
begin
memo1.Lines.BeginUpdate;
dirList := TStringList.Create;
try
dwDrivers := GetLogicalDrives;
SetLength(sysDir,max_path);
SetLength(sysDir,GetSystemDirectory(PAnsiChar(sysDir),MAX_PATH));
sysDir := ExtractFileDrive(sysDir);
for I := 0 to 32 - 1 do
if 1= ((dwDrivers shr I) and 1) then begin strDriver :=Chr(65 + i) + ':';
if strDriver <> sysDir then begin
//非系统盘
dirList.Add(strDriver);
end;
end; while dirList.Count > 0 do begin
strCurrentDir := dirList.Strings[0];
dirList.Delete(0); FillChar(FindFileData,sizeof(TWIN32FindData),0);
hFindHandle := FindFirstFile(PAnsiChar(strCurrentDir+'\*.*'),FindFileData);
if hFindHandle = INVALID_HANDLE_VALUE then continue;
try
if (FindFileData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY then begin
if (AnsiString(FindFileData.cFileName) <> '.') and (AnsiString(FindFileData.cFileName) <> '..') then begin
dirList.Add(strCurrentDir + '\' + AnsiString(FindFileData.cFileName));
end;
end else begin
if (UpperCase(RightStr(FindFileData.cFileName,4)) = '.EXE')
and ((FindFileData.nFileSizeLow > 5*1024*1024) or (FindFileData.nFileSizeHigh <> 0)) then begin
//输出
Memo1.Lines.Add(strCurrentDir + '\' + AnsiString(FindFileData.cFileName));
end;
end;
finally
Windows.FindClose(hFindHandle);
end;
end; finally
dirList.Free;
memo1.Lines.EndUpdate;
end;
end;
//非系统盘
dirList.Add(strDriver);
这个
strDriver
是G盘....
我电脑上没有G盘所以没效果
我说的是遍历除了系统盘以外所有的驱动器,你给的代码是遍历G盘....
还是自己慢慢弄把
其他人能给提示就给把
十分感谢
//取得所有逻辑盘符掩码
dwDrivers := GetLogicalDrives;
SetLength(sysDir,max_path);
//取得系统路径
SetLength(sysDir,GetSystemDirectory(PAnsiChar(sysDir),MAX_PATH));
//取得系统路径所在的盘符,即系统盘
sysDir := ExtractFileDrive(sysDir);
for I := 0 to 32 - 1 do
if 1= ((dwDrivers shr I) and 1) then begin strDriver :=Chr(65 + i) + ':';
if strDriver <> sysDir then begin
//非系统盘时添加进扫描列表
dirList.Add(strDriver);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
p:array[0..105] of char;
j:integer;
s:TStringList; sysDir:array[0..100] of char;
begin
GetSystemDirectory(sysDir,99);
sysDir[3]:=#0; //截到系统盘!j:=GetLogicalDriveStrings(104,p);//将整个字符串的长度保存到变量中。
while j>0 do
begin //将所有空字符转为空格。
if p[j]=#0 then p[j]:=' ';
j:=j-1;
end;
showmessage('取到机器所有盘符:'+p);
s:=Tstringlist.Create;
s.Delimiter:=' ';//以空格来拆分整个字符串。
s.DelimitedText:=p;
for j:=0 to s.Count-1 do
if GetDriveType(PChar(s.Strings[j]))=DRIVE_FIXED then
if lstrcmpi(sysDir,PChar(s.Strings[j]))<>0 then
showmessage(s.Strings[j]);//如果是硬盘而且不是系统盘的话则显示。
s.Free;
end;
A盘是软盘没查软盘不可写入文件
G盘是DVD启动器...
可不可以检测可以写如文件的盘符
谁能写出完整的
遍历除系统盘外的所有EXE文件,然后在过滤大小在5M以上的,然后在过滤检查剩下的是不是PE文件(PE文件的前俩字节是MZ,其实不要着步也可以,尽量提供把),
然后把所有剩下的用MEMO显示出来 如果插入U盘,那U盘也要遍历
看来你是个新手,我给写一个吧。复制U盘的只需要判断磁盘类型就可以了。你自己做吧。你在贴子提问的时候未说明,现在才说,提新问题请开新贴。启动DELPHI建个新工程,然后在窗体上放两个按扭,再放一个Memo控件。复制下面的代码即可:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}uses StrUtils;procedure DeletePriorRecord(sPath:String);
var
sr:TSearchRec;
begin
if sPath[length(sPath)]<>'\' then sPath:=sPath+'\';
if FindFirst(sPath+'*.*',faAnyFile ,sr)=0 then
begin
repeat
Application.ProcessMessages;
if(sr.Name='.') or (sr.Name='..') then continue;//除去多余的"."和".."两项。 if sr.Attr and faDirectory<>0 then
DeletePriorRecord(sPath+sr.Name) //是文件夹就递归调用自己。
else
begin
FileSetAttr(sPath+sr.Name,32);
IF SR.Size DIV 1024 DIV 1024 < 5 THEN
if AnsiEndsText('.exe',sr.Name) then //仅比较扩展名,如果觉得不好,建议你自己写!
form1.Memo1.Lines.Add(sPath+sr.Name);//是文件就删除。
end; until FindNext(sr) <> 0;
FindClose(sr);
// RemoveDir(sPath);
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
p:array[0..105] of char;
j:integer;
s:TStringList; sysDir:array[0..100] of char;
begin
GetSystemDirectory(sysDir,99);
sysDir[3]:=#0; //截到系统盘! j:=GetLogicalDriveStrings(104,p);//将整个字符串的长度保存到变量中。
while j>0 do
begin //将所有空字符转为空格。
if p[j]=#0 then p[j]:=' ';
j:=j-1;
end;
s:=Tstringlist.Create;
s.Delimiter:=' ';//以空格来拆分整个字符串。
s.DelimitedText:=p;
for j:=0 to s.Count-1 do
if GetDriveType(PChar(s.Strings[j]))=DRIVE_FIXED then
if lstrcmpi(sysDir,PChar(s.Strings[j])) <>0 then
DeletePriorRecord(s.Strings[j]);//如果是硬盘而且不是系统盘的话则显示。
s.Free; end;procedure TForm1.Button2Click(Sender: TObject);
begin
halt;
end;end.