Inno Setup - FileCopy use wildcard character in pathname

前端 未结 2 1257
臣服心动
臣服心动 2021-01-14 23:59

I\'m trying to copy all database files over from a previous installation to a new installation, which has a new pathname. The problem is that the installer will not know th

2条回答
  •  醉梦人生
    2021-01-15 00:05

    You need to use FindFirst, FindNext, and FindClose to iterate through the folder. You get each database name, and then copy it individually. An example of doing that in Pascal (Delphi) can be found here. There's also an example of using them in the InnoSetup help file, in the Support Functions Reference section on File System Functions:

    // This example counts all of the files (not folders) in the System directory.
    var
      FilesFound: Integer;
      FindRec: TFindRec;
    begin
      FilesFound := 0;
      if FindFirst(ExpandConstant('{sys}\*'), FindRec) then begin
        try
          repeat
            // Don't count directories
            if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
              FilesFound := FilesFound + 1;
          until not FindNext(FindRec);
        finally
          FindClose(FindRec);
        end;
      end;
      MsgBox(IntToStr(FilesFound) + ' files found in the System directory.',
        mbInformation, MB_OK);
    end;
    

    You can change the loop above to look in the proper old folder for each *.mdb (in the FindFirst call) and change the line that counts to a block that copies each file found into the new folder (using either FileCopy or a TFileStream, whichever you prefer).

提交回复
热议问题