Inno Setup: copy folder, subfolders and files recursively in Code section

Rafael LGC

Is there any way to browse and recursively copy/move all files and subdirectories of a directory within the code section? (PrepareToInstall)

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.

The Files section is executed at a later time when needed.

Martin Prikryl

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:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Inno Setup: pack folder with all subfolders

From Dev

Inno Setup Iterate over [Files] section in Pascal code

From Dev

Inno Setup Code section create hidden file

From Dev

Inno Setup [Code] section variable to [Registry]

From Dev

bash shell: recursively search folder and subfolders for files from list

From Dev

Python script recursively rename all files in folder and subfolders

From Dev

How to recursively copy only the files from folders and subfolders?

From Dev

Recursively count files in subfolders

From Dev

Copy files specified files with subfolders to another folder[BATCH]

From Dev

I need something like "skipifdoesntexist" within [Files] section in Inno Setup

From Dev

How to completely disable specific component in Inno Setup from code section?

From Dev

Inno Setup: How to pass variable from [Code] to [Run] (or other section)

From Dev

Inno Setup: How to pass variable from [Code] to [Run] (or other section)

From Dev

How to copy a subset of subfolders recursively

From Dev

How to copy specific files in a list from subfolders to a folder?

From Dev

How to copy files from folders and subfolders and paste to a single folder?

From Dev

Copy to clipboard in Inno Setup

From Dev

Inno-setup pack all files in a folder exept for 1 file

From Dev

Inno-setup pack all files in a folder exept for 1 file

From Dev

Inno Setup Copy Files and Folders to an Existing Zip File

From Dev

Inno Setup Section [Run] with condition

From Dev

Copy subfolders and files in msbuild

From Dev

Find all files, and copy them to a folder (Flatten recursively)

From Dev

Find all files, and copy them to a folder (Flatten recursively)

From Dev

Windows Command Copy all files recursively to a Main Folder

From Dev

Copy and rename files recursively using part of folder name for new name

From Dev

Copy files recursively from a hierarchy to a single flat folder

From Dev

Inno Setup: How to run a code procedure in Run section or before Run section?

From Dev

NSIS - how to recursively include all files only from source folder and subfolders?

Related Related

  1. 1

    Inno Setup: pack folder with all subfolders

  2. 2

    Inno Setup Iterate over [Files] section in Pascal code

  3. 3

    Inno Setup Code section create hidden file

  4. 4

    Inno Setup [Code] section variable to [Registry]

  5. 5

    bash shell: recursively search folder and subfolders for files from list

  6. 6

    Python script recursively rename all files in folder and subfolders

  7. 7

    How to recursively copy only the files from folders and subfolders?

  8. 8

    Recursively count files in subfolders

  9. 9

    Copy files specified files with subfolders to another folder[BATCH]

  10. 10

    I need something like "skipifdoesntexist" within [Files] section in Inno Setup

  11. 11

    How to completely disable specific component in Inno Setup from code section?

  12. 12

    Inno Setup: How to pass variable from [Code] to [Run] (or other section)

  13. 13

    Inno Setup: How to pass variable from [Code] to [Run] (or other section)

  14. 14

    How to copy a subset of subfolders recursively

  15. 15

    How to copy specific files in a list from subfolders to a folder?

  16. 16

    How to copy files from folders and subfolders and paste to a single folder?

  17. 17

    Copy to clipboard in Inno Setup

  18. 18

    Inno-setup pack all files in a folder exept for 1 file

  19. 19

    Inno-setup pack all files in a folder exept for 1 file

  20. 20

    Inno Setup Copy Files and Folders to an Existing Zip File

  21. 21

    Inno Setup Section [Run] with condition

  22. 22

    Copy subfolders and files in msbuild

  23. 23

    Find all files, and copy them to a folder (Flatten recursively)

  24. 24

    Find all files, and copy them to a folder (Flatten recursively)

  25. 25

    Windows Command Copy all files recursively to a Main Folder

  26. 26

    Copy and rename files recursively using part of folder name for new name

  27. 27

    Copy files recursively from a hierarchy to a single flat folder

  28. 28

    Inno Setup: How to run a code procedure in Run section or before Run section?

  29. 29

    NSIS - how to recursively include all files only from source folder and subfolders?

HotTag

Archive