Scenario: You need to create a folder tree, but only if it doesn’t exist. The path is stored as a string like this:
Var requiredPath As String = SpecialFolder.Documents.NativePath + "/MyNewRoot/MyNewChild"
When TargetWindows is true, you convert the slashes to backslashes, and clean it up, for example:
Var pathChar As String = “/"
If TargetWindows Then pathChar = “\"
// Regardless of OS and how the path was stored, it will always come out “clean”
requiredPath = requiredPath.ReplaceAll(“/",pathChar).ReplaceAll(“\",pathChar) // Convert all path delimiters to OS standardized
requiredPath = requiredPath.ReplaceAll(pathChar+pathChar,pathChar) // Remove duplicate path chars
Then, the moment of truth comes, and you attempt to create the FolderItem:
Var fi As FolderItem = new FolderItem( requiredPath )
- MacOS executes this line WITHOUT Exception.
- BUT Windows throws AN “UnsupportedFormatException”
- Apparently, Windows “new FolderItem” Is internally creating something like: SpecialFolder.Documents.Child(“MyNewRoot”).Child(“MyNewChild”)
- That construct would obviously throw an error since the .Child(“MyNewRoot”) would be a Nil object (and therefore cannot have .Child method).
- Is this a Xojo bug?
- Or is there some obscure reason why the “new FolderItem” is more robust on MacOS (even though cross-platform apps can’t enjoy the robustness)?