gpt4 book ai didi

inno-setup - 在代码部分中递归地设置Inno Setup : copy folder,子文件夹和文件

转载 作者:行者123 更新时间:2023-12-04 13:48:37 25 4
gpt4 key购买 nike

有什么方法可以浏览并递归复制/移动代码部分中目录的所有文件和子目录? (PrepareToInstall)

我需要忽略一个特定的目录,但是例如,使用xcopy它会忽略所有目录/default/,而我只需要忽略一个特定的目录。
Files部分在需要时稍后执行。

最佳答案

要以编程方式递归复制目录,请使用:

procedure DirectoryCopy(SourcePath, DestPath: string);
var
FindRec: TFindRec;
SourceFilePath: string;
DestFilePath: string;
begin
if FindFirst(SourcePath + '\*', FindRec) then
begin
try
repeat
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
begin
SourceFilePath := SourcePath + '\' + FindRec.Name;
DestFilePath := DestPath + '\' + FindRec.Name;
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
begin
if FileCopy(SourceFilePath, DestFilePath, False) then
begin
Log(Format('Copied %s to %s', [SourceFilePath, DestFilePath]));
end
else
begin
Log(Format('Failed to copy %s to %s', [SourceFilePath, DestFilePath]));
end;
end
else
begin
if DirExists(DestFilePath) or CreateDir(DestFilePath) then
begin
Log(Format('Created %s', [DestFilePath]));
DirectoryCopy(SourceFilePath, DestFilePath);
end
else
begin
Log(Format('Failed to create %s', [DestFilePath]));
end;
end;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end
else
begin
Log(Format('Failed to list %s', [SourcePath]));
end;
end;

添加您需要的任何过滤器。查看如何过滤 ...

有关使用示例,请参阅我对问题的回答:
  • Copying hidden files in Inno Setup
  • How to save a folder when user confirms uninstallation? (Inno Setup)
  • 关于inno-setup - 在代码部分中递归地设置Inno Setup : copy folder,子文件夹和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33391915/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com