Jump to content
Peter C

Copying Directory

Recommended Posts

Android 14

Delphi 12

 

Current I'm trying to copy from TPath.GetPublicPath + '/diary'  to TPath.GetSharedDocumentsPath  + '/backup'.

In the TPath.GetPublicPath + '/diary' I have some txt files that I wish to copy to TPath.GetSharedDocumentsPath  + '/backup'.

When I execute this code it works perfectly, no issues( takes around 2~3sec depending on how many txt files there are to transfer ).

But if I repeat the process, nothing happens. It executes and completes instantly.

So I manually deleted all the files in the TPath.GetSharedDocumentsPath  + '/backup' Folder to see if this was the case.

Executed the code, same result, nothing is copied.

So then I restarted the phone.

Code executes perfectly and all files copy.

Try again and back to square 1.

If my App creates another txt file, and then executes said code, only the newly created file copies across!

 

Even if I take the Thread Instance out and replace MyThread.Start with  TDirectory.Copy( MASTER_PATH, BACKUP_PATH ) the same issue occurs.

 

Am I missing something here?( Well obviously otherwise......)

 

 

procedure TSERTEC_DIARY.FormCreate(Sender: TObject);
begin
  MASTER_PATH                       := TPath.GetPublicPath + '/diary';
  ARCHIVE_PATH                      := MASTER_PATH + '/archive';
  BACKUP_PATH                       := TPath.GetSharedDocumentsPath + '/backup';
end;

 

procedure TMyBackgroundThread.Execute;
begin
  TDirectory.Copy( MASTER_PATH, BACKUP_PATH );
end;

 

procedure TSERTEC_DIARY.lbBACKUPClick(Sender: TObject);
var
  MyThread: TMyBackgroundThread;

begin
  MyThread                 := TMyBackgroundThread.Create(True); // Create suspended
  MyThread.FreeOnTerminate := True; // Auto-free thread when done
  rcPopup.Visible          := false;
  rcPopup.Opacity          := 0;
  if TDirectory.Exists( BACKUP_PATH ) then
  begin
    try
      try
        ListView1.Opacity          := 0.5;
        bkActivityCircle.Visible   := true;
        bkActivityFloatAni.Enabled := true;
        MyThread.Start; // Start the background thread
      except
        ShowMessage('Incorrect source path or destination path');
      end;
    finally
      ListView1.Opacity          := 1;
      bkActivityCircle.Visible   := false;
      bkActivityFloatAni.Enabled := false;
      ShowMessage('Backup Complete...');
    end;
  end else
  begin
    try
      try
        TDirectory.CreateDirectory( BACKUP_PATH );
      except
        ShowMessage('Unable to create path');
      end;
    finally
      try
        try
          ListView1.Opacity          := 0.5;
          bkActivityCircle.Visible   := true;
          bkActivityFloatAni.Enabled := true;
          MyThread.Start; // Start the background thread

        except
          ShowMessage('Incorrect source path or destination path');
        end;
      finally
        ListView1.Opacity          := 1;
        bkActivityCircle.Visible   := false;
        bkActivityFloatAni.Enabled := false;
        ShowMessage('Backup Complete...');
      end;
    end;
  end;
end;

Share this post


Link to post
14 hours ago, Peter C said:

Even if I take the Thread Instance out and replace MyThread.Start with  TDirectory.Copy( MASTER_PATH, BACKUP_PATH ) the same issue occurs.

Have you tried calling the overloaded version of TDirectory.Copy() that takes an IgnoreErrors parameter and set it to False? The overload of TDirectory.Copy() that you are calling implicitly uses IgnoreErrors=True.  When IgnoreErrors=False then a failure to copy files will raise an EInOutError exception, containing a list of all the files that failed to copy and the reason(s) why they couldn't be copied.  Are you getting that exception?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×