CopyTo and MoveTo overwrite issue

I noticed when using FolderItem.CopyTo and/or FolderItem.MoveTo and the file already exists, it does not overwrite the file.
Not sure if this is a Windows 10 only issue. I think it did work with Windows 8.1 though (not sure because I do not have Windows 8.1 anymore)

A solution for now is to use the shell: “copy /y sourcefilePath destinationfilePath”

BTW works fine with any OSX version.

Is this a know issue? Could not find a feedbackcase for this.

Huh. I wrote code yesterday using both MoveFileTo and CopyFileTo in a Web app for Linux. Maybe I need to double check that the overwrite works…

I only seen this issue when running Windows 10
OSX works as expected. Never tried Linux though.

[quote=207127:@Christoph De Vocht]I noticed when using FolderItem.CopyTo and/or FolderItem.MoveTo and the file already exists, it does not overwrite the file.
Not sure if this is a Windows 10 only issue. I think it did work with Windows 8.1 though (not sure because I do not have Windows 8.1 anymore)

A solution for now is to use the shell: “copy /y sourcefilePath destinationfilePath”

BTW works fine with any OSX version.

Is this a know issue? Could not find a feedbackcase for this.[/quote]

Confirmed. Indeed it fails silently.

The workaround without shell is to delete the destination if it exists before copying or moving.

if dest.exists then dest.Delete

You should definitely file a bug report. It affects 2015R3b2 I tried with as well under Windows 10.

<https://xojo.com/issue/40455>

In my experience this does not always work. Most certainly with larger files. I tried this several times.

The only way I got it working all the time was using the shell (copy).

Forgotten to add:
It returns 0 for .LastError (indicating it was succesfully).

This one is in my personal library, and could easily be modified as Michel said.

[code]Function CopyFileOrFolder(SourcePath as string, DestinationPath as String) As Boolean
try
dim source as new folderitem(SourcePath,3)
dim destination as new FolderItem(DestinationPath,3)
Dim newFolder As FolderItem
If source.Directory then //it’s a folder
// newFolder = destination.Child(source.Name)
newFolder = Destination
newFolder.CreateAsFolder
if not newFolder.Exists or not newFolder.Directory Then
// folder was not created - abort
Return False
End If
For i As Integer = 1 To source.Count //go through each item
Dim sourceItem as FolderItem = source.TrueItem(i)
If sourceItem = nil Then
// inaccessible
Return False
End If
// recursive
If not CopyFileOrFolder (sourceItem.nativepath, newFolder.nativepath) Then
//copy operation failed
Return False
End If
Next
Else //it’s not a folder
source.CopyFileTo destination
End if
Return True

	  catch err as RuntimeException
	    Return False
	  end try
	End Function[/code]

I can’t try it at the moment, but does Xojo.IO.FolderItem raise exceptions in this situation?

Will test it next Monday, since I haven’t Win10 VM installed on my Macbook.
But, @Paul Lefebvre it cannot be the case that new problems with clasic framework are not going to be researched anymore, since this is existing code in lots of applications.

Of course not. I don’t think any such thing was said.

[quote=207145:@Christoph De Vocht]In my experience this does not always work. Most certainly with larger files. I tried this several times.

The only way I got it working all the time was using the shell (copy).[/quote]

You can also use the shell just to delete the file.

I just tried. Discovered in the process that Xojo.io.Specialfolder does not support Desktop and is too iOS Centric for desktop.

Runtime Exception error 80.

Yeah, your best bet is to get a classic FolderItem to the location you want and then create a Xojo.IO.FolderItem from it:

Dim file1 As FolderItem = SpecialFolder.Desktop.Child("test") Dim file2 As New Xojo.IO.FolderItem(file1.NativePath)

I’m also on a laptop without a Windows 10 VM, so I can’t try it myself at the moment.

[quote=207178:@Paul Lefebvre]Yeah, your best bet is to get a classic FolderItem to the location you want and then create a Xojo.IO.FolderItem from it:

Dim file1 As FolderItem = SpecialFolder.Desktop.Child("test") Dim file2 As New Xojo.IO.FolderItem(file1.NativePath)

I’m also on a laptop without a Windows 10 VM, so I can’t try it myself at the moment.[/quote]

That is exactly what I did. But I still feel we should be able to keep it in the new framework family, as it where.

40458 - Please support all desktop paths with Xojo.IO.SpecialFolder
Status: Needs Review Rank: Not Ranked Product: Xojo Category: N/A

Michel Bujardet Today at 7:04 PM

I just wanted to use Xojo.IO.FolderItem constructor with Xojo.IO.SpecialFolder to point to a file on the Desktop, to keep everything new framework.

Unfortunately, Xojo.IO.SpecialFolder supports only iOS paths.

As a result, I had to use the classic SpecialFolder path in the constructor. Does not feel right.

Please add all the paths supported by classic SpecialFolder to Xojo.IO.SpecialFolder.

<https://xojo.com/issue/40458>

I can now confirm this is an Windows 10 issue only. CopyTo or CopyMove does not overwrite an existing file (without return an error)

This is issue that can/will break a lot of apps I guess.

I have the same. Workarround is not a big issue but you have to force endusers to install new build if they move to Win10.

[quote=207174:@Paul Lefebvre] @Joost Rongen But, @Paul Lefebvre it cannot be the case that new problems with clasic framework are not going to be researched anymore, since this is existing code in lots of applications.

Of course not. I don’t think any such thing was said.[/quote]
Sorry Paul, you’re right here, but I do get a bit nervous of this sort of issues with application in the field.