Kastri icon indicating copy to clipboard operation
Kastri copied to clipboard

In TStartupCopy, provide a way to copy all files in a folder

Open MyBuzzTechnologies opened this issue 1 month ago • 3 comments

The current TStartupCopy class works brilliantly. However, if I want to copy (replace) all files in a specific folder or sub-folder, I need to first retrieve a list of their names and pass as the first parameter into CopyDocuments() which does the same.

To save this step and make the use easier, if the AFilenames parameter is passed as an empty array, could it copy all files?

e.g.: (Not the most efficient implementation. Just an example)

for LSourceFileName in TDirectory.GetFiles(LSourcePath, '*.*', TSearchOption.soTopDirectoryOnly) do
begin
      LIndex := IndexStr(TPath.GetFileName(LSourceFileName), AFileNames);
      if (Length(FileNames) = 0) or (LIndex > -1) then
        TFile.Copy(LSourceFileName, TPath.Combine(LDestPath, AFileNames[LIndex]), True);
end;

MyBuzzTechnologies avatar Nov 10 '25 16:11 MyBuzzTechnologies

I'm considering making these changes. For Android, on line 73:

        if (Length(AFileNames) = 0) or MatchStr(LFileName, AFileNames) then

For iOS on line 124:

      if (LIndex > -1) or (Length(AFileNames) = 0) then

This should result in all files in the folder being copied using, for example:

TStartupCopy.CopyDocuments([], 'SomeFolder'); 

..but I'm yet to test it and wanted your comments anyway

DelphiWorlds avatar Nov 10 '25 19:11 DelphiWorlds

Thanks Dave, that solution would work so happy with it.

The only tweak could be a performance improvement due to the extraneous LIndex calculation on iOS unless it could be inlined into the if statement and checked after Length(AFilenames) = 0 so it doesn’t happen unless AFilenames isn’t empty.

Hope that makes sense

Sent from Outlook for iOShttps://aka.ms/o0ukef


From: DelphiWorlds @.> Sent: Monday, November 10, 2025 7:47:10 PM To: DelphiWorlds/Kastri @.> Cc: MyBuzz Technologies Ltd @.>; Author @.> Subject: Re: [DelphiWorlds/Kastri] In TStartupCopy, provide a way to copy all files in a folder (Issue #312)

[https://avatars.githubusercontent.com/u/22670829?s=20&v=4]DelphiWorlds left a comment (DelphiWorlds/Kastri#312)https://github.com/DelphiWorlds/Kastri/issues/312#issuecomment-3513627211

I'm considering making these changes. For Android, on line 73:

    if (Length(AFileNames) = 0) or MatchStr(LFileName, AFileNames) then

For iOS on line 124:

  if (LIndex > -1) or (Length(AFileNames) = 0) then

This should result in all files in the folder being copied using, for example:

TStartupCopy.CopyDocuments([], 'SomeFolder');

..but I'm yet to test it and wanted your comments anyway

— Reply to this email directly, view it on GitHubhttps://github.com/DelphiWorlds/Kastri/issues/312#issuecomment-3513627211, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AI5MEYGXF4FIHL4TLHVASA334DTT5AVCNFSM6AAAAACLVW62GCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKMJTGYZDOMRRGE. You are receiving this because you authored the thread.Message ID: @.***>

MyBuzzTechnologies avatar Nov 10 '25 19:11 MyBuzzTechnologies

Too early in the morning. I've just realised the iOS part would not work anyway. I'll come up with something else, like this:

    for LSourceFileName in TDirectory.GetFiles(LSourcePath, '*.*', TSearchOption.soTopDirectoryOnly) do
    begin
      if Length(AFileNames) > 0 then
      begin
        LIndex := IndexStr(TPath.GetFileName(LSourceFileName), AFileNames);
        if LIndex > -1 then
          TFile.Copy(LSourceFileName, TPath.Combine(LDestPath, AFileNames[LIndex]), True);
      end
      else
        TFile.Copy(LSourceFileName, TPath.Combine(LDestPath, TPath.GetFileName(LSourceFileName), True));
    end;

DelphiWorlds avatar Nov 10 '25 20:11 DelphiWorlds