Inno setup Inno设置-FileCopy在路径名中使用通配符

Inno setup Inno设置-FileCopy在路径名中使用通配符,inno-setup,wildcard,pascal,file-copying,delphi,Inno Setup,Wildcard,Pascal,File Copying,Delphi,我正在尝试将所有数据库文件从以前的安装复制到具有新路径名的新安装。问题是安装程序不知道数据库文件的名称,所以我尝试使用通配符 我尝试使用TFileStream.Create(),但这是在搜索单个文件,例如“*.mdb”,我不断收到一个错误,说它找不到该文件。我也尝试过使用FileCopy(),但它似乎失败了,继续前进。我甚至尝试使用通过命令行运行它,但它只会冻结安装 我在网上搜索了很长时间,寻找答案,并阅读了大量文档。我只需要知道如何使用通配符来复制名称未知的文件。下面是我尝试过的例子 TFil

我正在尝试将所有数据库文件从以前的安装复制到具有新路径名的新安装。问题是安装程序不知道数据库文件的名称,所以我尝试使用通配符

我尝试使用TFileStream.Create(),但这是在搜索单个文件,例如“*.mdb”,我不断收到一个错误,说它找不到该文件。我也尝试过使用FileCopy(),但它似乎失败了,继续前进。我甚至尝试使用通过命令行运行它,但它只会冻结安装

我在网上搜索了很长时间,寻找答案,并阅读了大量文档。我只需要知道如何使用通配符来复制名称未知的文件。下面是我尝试过的例子

TFileStream.Create()文件

FileCopy()

命令行

    Exec('cmd.exe', 'COPY "C:\Users\seang\Desktop\Old\*.mdb" "C:\Users\seang\Desktop\New\*.mdb"', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);

您需要使用
FindFirst
FindNext
FindClose
来遍历文件夹。获取每个数据库名称,然后分别复制它。可以在Pascal(Delphi)中找到这样做的示例。InnoSetup帮助文件中也有一个使用它们的示例,在
文件系统功能的
支持功能参考
部分中:

// 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;

您可以更改上面的循环以查找每个
*.mdb
(在
FindFirst
调用中)的正确旧文件夹,并将计数行更改为将找到的每个文件复制到新文件夹中的块(使用
FileCopy
TFileStream
,以您喜欢的为准).

如果稍加修改,命令行尝试可以正常工作:

Exec('cmd.exe', '/c COPY "C:\Users\seang\Desktop\Old\*.mdb" "C:\Users\seang\Desktop\New"', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);

令人惊叹的!非常好,非常感谢。在查看您的帖子后,我搜索了FindFirst,并找到了该帖子的Inno安装文档。我想我看起来不够努力。谢谢你的帮助!有关完整的代码(包括递归),请参阅
// 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;
Exec('cmd.exe', '/c COPY "C:\Users\seang\Desktop\Old\*.mdb" "C:\Users\seang\Desktop\New"', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);