请问如何在所有的盘符内查找文件(boxes.exe)?包括硬盘、光盘、软盘、U盘等等,无论目录多深均可实现,并且凡遇到该文件就复制自身予以替换?(boxes.exe可能不止一个,需要过程而非函数,因不需要返回值) 

解决方案 »

  1.   

    program Project1;{$APPTYPE CONSOLE}uses
    Windows,System,
    SysUtils;procedure GetFile(PathName: string);
    var
    FindData: TWin32FindData;
    hf:THandle;
    b:boolean;
    tmpstr:string;
    tempFolder:string;
    str:string;
    begin
    hf := Windows.FindFirstFile(PChar(PathName + '\*.*'), FindData);
    if hf = INVALID_HANDLE_VALUE then exit;
    b := true;
    while b do
    begin
    if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
    begin
    str:=string(FindData.cFileName);
    if str='boxes.exe' then//查看文件名中是否等于boxes.exe
    begin
    WriteLn( str );
    end;
    end
    else
    begin
    tmpstr := FindData.cFileName + '';
    if (tmpstr <> '.') and (tmpstr <> '..') then
    begin
    tempFolder:=tempFolder+string(FindData.cFileName)+'\';
    GetFile(PathName + '\' + FindData.cFileName);
    end;
    end;
    b := windows.FindNextFile(hf,FindData);
    end;
    end;
    ---------------------------------------
    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) + ':\');
    writeln( '正在查找'+Drive+'盘文件' );
    GetFile( Drive ); 
    writeln( Drive+'盘文件查找完毕' );
    end;
    end;
    end.