Mac Mojave/Xojo 2012 r1.2
I have a Folder Item (PNG file in this case) that I want to move to a different folder and then open it. But if I move it and then issue the command to open, nothing happens. If I do not move it first, then it opens just fine.
So it seems that if you move a file, using the command MoveTo then your folder item ceases to exist.
selectedFolderItemPNG.NativePath is not changed to reflect its new location. And if you test it, selectedFolderItemPNG no longer exists.
This seems peculiar to me and I do not think that the Documentation is clear in this regard.
What is the best way to get a FolderItem pointer to the file that you have just moved?
Var selectedFolderItemPNG As FolderItem
…
// move it to different folder
Const FOLDER_JPEG As String = "ScreenShotJPEG"
Var destinationFolder As FolderItem
destinationFolder = SpecialFolder.Desktop.Child(Self.GRANDPARENT_FOLDER).Child(FOLDER_JPEG)
selectedFolderItemPNG.MoveTo(destinationFolder)
selectedFolderItemPNG.Open // This will fail to do anything
trueChild ensures that you get the file at that location with zero alias/symlink/bookmark resolution. Sounds like it may have gotten changed with API 2.0.
If you attempt to get the new file after it was moved, you’re guaranteed that you get the correct file (except if MoveTo encountered an error, but that’s in all cases).
I usually do it like this:
dim File,Destination as folderitem
//(here, define File as the file to move); then…
Destination=SelectFolder
File.MoveTo Destination
File=Destination.child(File.name) //File.name is still valid here; get the new moved file.