Inno Setup-FileCopy在路径名中使用通配符 [英] Inno Setup - FileCopy use wildcard character in pathname

查看:411
本文介绍了Inno Setup-FileCopy在路径名中使用通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 the names of the database files, so I'm trying to use a wildcard character.

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

I tried using TFileStream.Create(), but this was searching for a single file, such as "*.mdb", and I kept getting an error saying it couldn't find that file. I also tried using FileCopy(), but it seems to simply fail and move on. I even tried using Exec() to run it through command line, but it would just freeze the installation.

我已经在网上搜索了很长时间了,并仔细阅读了很多文档。我只需要知道如何使用通配符来复制名称未知的文件。下面是我尝试过的示例。

I've searched online a long time for an answer and read through a lot of the documentation. I just need to know how I can use a wildcard character to copy files with unknown names. Below are examples of what I've tried.

TFileStream.Create()

TFileStream.Create()

    OldDBs := 'C:\Users\seang\Desktop\Old\*.mdb';
    NewDBs := 'C:\Users\seang\Desktop\New\*.mdb';
    SourceDB:= TFileStream.Create(OldDBs, fmOpenRead);
    DestDB:= TFileStream.Create(NewDBs, fmCreate);
    DestDB.CopyFrom(SourceDB, SourceDB.Size);
    SourceDB.Free;
    DestDB.Free;

FileCopy()

FileCopy()

    FileCopy('C:\Users\seang\Desktop\Old\*.mdb', 'C:\Users\seang\Desktop\New\*.mdb', True);

命令行

    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帮助文件的文件系统功能支持功能参考 c部分中,还有一个使用它们的示例:

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;

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

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).

这篇关于Inno Setup-FileCopy在路径名中使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆