Uploading same file to Google drive creates a duplicate

When uploading the same named file to Google Drive, it creates a duplicate. More correct, it creates a new version of the file. Can you suggest a way to force replacement of the existing file so that only one version remains?

You have previously provided a perfect solution to a somewhat similar issue with Dropbox:

It does not seem to be possible to delete a file in cloud storage with FNC CloudPack; such an option would solve the problem. (Likewise seemingly no option to rename or move files in cloud storage.)

Hi,

Unfortunately the Google Drive API does not currently provide an option to overwrite an existing file with the same name.

However it does provide the functionality to delete files from the drive with the "Delete(TTMSFNCCloudItem)" method.

Example:

procedure TForm1.Button1Click(Sender: TObject);
var
  di: TTMSFNCCloudGoogleDriveItem;
  I: integer;
begin
  for I := 0 to TMSFNCTreeView1.SelectedNodeCount - 1 do
  begin
    if Assigned(TMSFNCTreeView1.SelectedNodes[I]) and Assigned(TMSFNCTreeView1.SelectedNodes[I].DataObject) then
    begin
      di := TTMSFNCCloudGoogleDriveItem(TMSFNCTreeView1.SelectedNodes[I].DataObject);
      TMSFNCCloudGoogleDrive1.Delete(di);
    end;
  end;
end;

Thank you Bart. Your code will do the trick!