MoveFileTo problem

I’ve got the following code in an app I’m trying to move from RS to Xojo and it is no longer working in Xojo. I’ve tried from 2013R2 thru the current beta with no success. What I’m seeing is that the code executes with no exception being raised but the file isn’t being moved. If someone else can confirm they are seeing this I will file the feedback report. I’m running OS X 10.6.8.

Thanks!

Dim Fi As FolderItem
Dim File As FolderItem

Fi = GetFolderItem(DestLoc, FolderItem.PathTypeNative)
File = GetFolderItem(CurrentLoc, FolderItem.PathTypeNative)
If Fi <> Nil Then
Try
File.MoveFileTo(Fi)
Catch ex As IOException
MsgBox “Blah”
End Try
End If

Are the source and destination on the same volume?

MoveFileTo does not throw an Exception. Check the File.LastErrorCode property to see what went wrong.

Thanks Greg. I will check the LastErrorCode and report that back here. Yes, both files are on the same volume. In this particular case they are in subfolders from a main folder.

Ok, the error was a 101 - File not found. It was my fault. I had a previous GetFolderItem(“filename”) with no pathMode parameter which was a holdover from the old code.

Running this in the IDE was giving the NativePath as “/Users/dev/Documents/Xojo Projects/prj/:Users:dev:Documents:CD:Drop Folder” - so to me it looks like I’ve gotten a combination of AbsolutePath and NativePath without the pathMode parameter - is this intended behavior or should I file a feedback report?

[quote=41529:@Michael Bierly]Ok, the error was a 101 - File not found. It was my fault. I had a previous GetFolderItem(“filename”) with no pathMode parameter which was a holdover from the old code.

Running this in the IDE was giving the NativePath as “/Users/dev/Documents/Xojo Projects/prj/:Users:dev:Documents:CD:Drop Folder” - so to me it looks like I’ve gotten a combination of AbsolutePath and NativePath without the pathMode parameter - is this intended behavior or should I file a feedback report?[/quote]

GetFolderItem has to default to the ‘legacy’ path style for compatibility reasons, so passing in a native path will yield ‘incorrect’ results.

Thanks Joe. That makes sense why it does what it does.

This is for Paul - maybe this should be part of the list of things in the upgrade guide. (I haven’t looked at it since the original). I will bet that others will get bit on this upgrading their apps from RS to Xojo. As careful as I thought I was migrating my old code, I still ended up missing one that needed to be changed.

[quote=41529:@Michael Bierly]Running this in the IDE was giving the NativePath as “/Users/dev/Documents/Xojo Projects/prj/:Users:dev:Documents:CD:Drop Folder”
ReplaceAll( ,":","/") before accessing the Nativepath.

This is why I prefer using AbsolutePath over NativePath, it seems to work more reliably.

What are you seeing not working reliably?

Please note that absolutepath will not work in future releases, probably.

AbsolutePath is deprecated in the sense that we don’t encourage future use, but we don’t have plans to remove it.

I see problems such as the one mentioned, as well as issues with SMB:// mounted volumes and inconsistencies in how the paths are reported back.

Hi Joe, thanks for the note. :slight_smile:

Hello guys,

Probably that i`ll get bumps again from the team because of pig tailing the thread but i get the same issue.

No mater whatever i put in the path im getting the same 101 Error , ive tried all the options and i get the same error, really its a pain to upgrade a project from RealBasic to XOJO, i wish it was a better way of doing this, and when you have to deal with more than 100 k lines of code its a programmer nightmare.

the last atempt is something like this

 [code]   fi = app.patientFolderItem.child(code).child("photos")
    file = photoFolderItem
    
    file.MoveFileTo(fi)

MsgBox "Moving photo error code : " + EndOfLine + Str(file.LastErrorCode)

[/code]

and on the fi and file i get the right path and when i put in the code the message box i get 101

when i look in the debug i get all the paths the right ones native, shell and absolute, but the code does not work, it does not move the file.

What can i do in this case ?

I`m running XOJO 2014R3.2

Thanks

Does the target filepath actually exist?

If not you should create it before the move.

[quote=161599:@Simon Berridge]Does the target filepath actually exist?

If not you should create it before the move.[/quote]
Yes it does , i`m creating a simple project to replicate the issue to see from where it comes.

Well it seems that it gets the same issue like as always , AbsolutePath vs NativePath , if i force all the paths to be native it works well, otherwise it crashes and trows the 101 error.

Just out of curiosity, could you post the AbsolutePath of the source and destination file in your sample project?

AbsolutePath has been deprecated for a while. It should not be used.

Not seeing all of the code this is tough to answer. I have a couple of apps that do a lot of MoveFIleTo executions and have no problems whatsoever. Here is the method in one where it moves all of the html pages from one folder to another as a backup measure before modifying the html pages. This app has moved thousands of files over the years without any problems.Maybe something in this will give you a clue as to what your problem is:

[code] movePages(f As FolderItem, t As FolderItem) As Boolean
// This routine moves the html page files for the category being processed
// from the f, from, folder to the t, to folder. Usually this will be from the
// “browser” folder to the “old pages” folder within the “browser” folder; but,
// if an error occurs during processing after the original files were moved to the
// “old pages” folder, this same routine can be called to move things back where
// the “old pages” becomes the f, from, folderitem and the “browser” folder is
// the t, to, folderitem. Invoked from the rebuildTheCategory method
Dim fFrom, fTo As FolderItem
Dim i, nameLength, num As Integer
Dim fName, pageNameToFind, s As String

movedCount = 0 // how many files moved to the t (to) folder
pageNameToFind = catToDo.pageName // page name we are looking for, minus sequence #
nameLength = Len(pageNameToFind) // length of this page name
num = f.Count
for i = num DownTo 1 // walk through items in f (from) folder
fFrom = f.TrueItem(i)
if fFrom <> nil then
if fFrom.exists and fFrom.Visible and fFrom.IsReadable and not fFrom.Directory then
fName = fFrom.Name
if mid(fName,1, nameLength) = pageNameToFind then
fTo = t.child(fName)
if fTo.exists and fTo.visible and fTo.IsReadable and not fTo.Directory then
deleteCount = deleteCount +1 // delete any existing file in the to folder
fTo.Delete
end if
fFrom.MoveFileTo t
if fFrom.LastErrorCode <> 0 then
s = "In movePages method of wPicInfo window moving files from folder " + f.Name
s = s + " to folder " + t.Name + " - "
s = s + fldrItemError(fFrom.LastErrorCode) // add kind of error to msg string
s = s + “Execution cannot continue normally.”
showAlertDialog kPgmErr, s, “Okay”, “”, “”, “a”, “”, 2
return false
end if
movedCount = movedCount + 1
end if // mid…
end if // fFrom.exists and …
end if // fFrom <> nil
next i
return true
[/code]