I’ve started to replace some bad code I wrote in RB many years ago eg.
Old code (still works fine):
myfolderItem = getfolderItem(f.absolutePath + "xFile.txt")
if myfolderItem.exists then
// do this
else
// goes here if file doesn't exist
// (all good!)
New code (crashes program):
myfolderItem = f.child("xFile.txt")
if myfolderItem.exists then
// fine if file exists
else
// never goes here if file doesn't exist
//exits with error
The above causes an error if myfolderItem is a file but not if it is a folder.
So should I be using -
folders: if myfolderItem.exists
files: if myFolderItem <> Nil
Or is it worth just using both tests in both situations
if myFolderItem <> Nil And myFolderItem.exists
This is a shame because I have so many of these in this project that I have to manually change. I was hoping to just do find/replace.
BTW: If I replace AbsolutePath with Nativepath the program breaks on Mac so please don’t go there at this time.
This exercise is about having one set of code that avoids NativePath and AbsolutePath so the program can be compiled in old and new Xojo IDE for an old and new systems.