Inno Setup:在“代码"部分以递归方式复制文件夹,子文件夹和文件 [英] Inno Setup: copy folder, subfolders and files recursively in Code section
问题描述
有没有办法浏览和递归复制/移动代码部分中目录的所有文件和子目录? (PrepareToInstall
)
Is there any way to browse and recursively copy/move all files and subdirectories of a directory within the code section? (PrepareToInstall
)
我需要忽略特定目录,但是例如,使用xcopy
它将忽略所有目录/default/
,而我只需要忽略特定目录.
I need to ignore a specific directory, but using xcopy
it ignores all directories /default/
, for example, and I need to ignore a specific only.
Files
部分在以后需要时执行.
The Files
section is executed at a later time when needed.
推荐答案
要以编程方式递归复制目录,请使用:
To recursively copy a directory programmatically use:
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;
添加您需要的任何过滤条件.查看.
和..
的过滤方式.
Add any filtering you need. See how the .
and ..
are filtered.
有关使用示例,请参阅我对问题的回答:
For an example of use, see my answers to questions:
- Copying hidden files in Inno Setup
- How to save a folder when user confirms uninstallation? (Inno Setup).
这篇关于Inno Setup:在“代码"部分以递归方式复制文件夹,子文件夹和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!