This works perfectly for me on 26.5.1 (ARM). In fact, I have this sort of code all over the project I’m currently focused on and it worked through all of the betas.
macOS: Fixed the use of chained Child methods over a valid FolderItem on macOS; so its behavior adheres what is described in the documentation and also matches the current behavior of Windows and Linux. Now, if some of the intermediate Child calls for the path chain doesn’t exist, it returns Nil. (81294
var f as FolderItem
f = SpecialFolder.Desktop
var tempf as FolderItem
tempf = f.child(“test”).child(“thisisafile.txt”)
//msgbox tempf.NativePath
if tempf.Exists = false then
msgbox “does not exist”
end
It now returns a NIL for tempf
Although the temp file does not exists, it is a valid folderitem. Why would this return NIL? If this is now intended, what is the need for .exists? This will break code for sure.
This also provides an opportunity to either create the entire path or provide a more useful error message to the user since you should be checking every item in the path.
No. There’s a difference between an invalid path (or an uninitialized variable which contains no value) and a non-existent file at a valid path. The parent directory doesn’t exist, so the child would be invalid, not just non-existent.
While this change is good for consistency, it sucks logically. I expect it does this due to some underlying behavior on other platforms, but it still doesn’t make sense.
I don’t use Mac but this is how Xojo has operated on Windows for as long as I’ve known it so I’ve just got used to it.
If you consider that Xojo doesn’t have methods to create a full path all in one go, then it actually makes sense.
Non-existent children of folders have to return valid FolderItem objects with Exists = False, as you need the object reference to be able to call .CreateFolder to create the path step-by-step going downwards.
Going one step beyond a non-existent child creates an invalid path and returns Nil, so that you can’t pass this as an invalid target for operations like .CopyTo and .MoveTo
I do most of my work on Windows and Linux but also use macOS and I have always expected this behavior as @Lawrence_Johnson and @Anthony_G_Cyphers have described.