MoveFileTo file and Overwrite

Hi everyone
I need to copy file and overwrite the one on target location
But nothing happens…
I’v check, the file is well hook ( It work if the original is delete before)
But manually delete it before, is not a good practice ( seen in this tread )
https://forum.xojo.com/24843-copyto-and-moveto-overwrite-issue )

I can’t use shell because i’m operating from OSX and ( BOTH files are on windows server )
So what is the workAround ?
With XOJO 2013 4.1
Thanks

[code] if ListboxDrop.ListCount >=1 then

Dim pathToOriginFile As FolderItem
Dim pathToTempFolder As FolderItem

Dim pathToTempFileString As String
Dim pathToTempFile As FolderItem

//get path of tempFolder from the first row ( reserve for that purpose )
pathToTempFolder = GetFolderItem(ListboxDrop.Cell(0,4),FolderItem.PathTypeURL)

for i as integer = 1 to ListboxDrop.ListCount-1
  
  //get path of origin file from listbox.Cell
  pathToOriginFile = GetFolderItem(ListboxDrop.Cell(i,4),FolderItem.PathTypeURL)
  
  //Construct path of file in tempFolder
  pathToTempFileString = pathToTempFolder.URLPath+ListboxDrop.Cell(i,0)
  pathToTempFile = GetFolderItem(pathToTempFileString,FolderItem.PathTypeURL)
           
  pathToTempFile.MoveFileTo(pathToOriginFile.Parent)
  
next

end[/code]

Why not delete the file on destination first ?

Just verify the file exists, and if such, delete it, then do your moveFile.

Note that the delete may not be instantaneous. You may want to use a timer, to do the move after a small delay.

Because i try to learn from forum advice… :slight_smile:
https://forum.xojo.com/24843-copyto-and-moveto-overwrite-issue

I don’t like timer ( it may add delay where it doesn’t needed )… But if it’s Solution !
And what about a loop checking exist… until false ?

[quote=324463:@Denis Despres]Because i try to learn from forum advice… :slight_smile:
https://forum.xojo.com/24843-copyto-and-moveto-overwrite-issue

I don’t like timer ( it may add delay where it doesn’t needed )… But if it’s Solution !
And what about a loop checking exist… until false ?[/quote]

Loop is a user interface killer. While loop executes, the app is frozen.

In a modern event driven language such as Xojo, timers are the only sensible and natural way of waiting for a condition. You can perfectly check until false, for instance in a 100ms timer (1/10th a second).