File deletion works as 32bit app but fails as 64bit app?

On my Mac and using Xojo 2018R3 on MacOS X 10.12.6 Sierra I have an app that can be reset and deletes its preference file and its applicationSupport folder. It works just fine when I compile it as a 32bit app but fails (while claiming success) as a 64bit app. Any idea what I am overlooking?

The code is:

[code]dim plistDeleted as Boolean
dim TestAppSupportFolderDeleted as Boolean

// delete the plist file

Dim MyDeleteFile As FolderItem = SpecialFolder.Preferences.Child(“com.MyCompany.TestApp.plist”)

if MyDeleteFile <> Nil and MyDeleteFile.Exists then

MyDeleteFile.Delete()

If MyDeleteFile.LastErrorCode > 0 then
MsgBox Str( MyDeleteFile.LastErrorCode )
CB_TestApp_plist.State = CheckBox.CheckedStates.Unchecked
plistDeleted = False

Else
CB_TestApp_plist.State = CheckBox.CheckedStates.Checked
plistDeleted = True
End if

else
MsgBox "File doesn’t exist: " + MyDeleteFile.Name
end if

// delete thefolder and its contents

Dim MyDeleteFile2 As FolderItem = SpecialFolder.ApplicationData.Child(“TestApp”)

dim returnCode as Integer

if DeleteEntireFolder( MyDeleteFile2 ) > 0 then
MsgBox Str( MyDeleteFile2.LastErrorCode )
CB_TestApp_ApplicationSupport_TestAppfolder.State = CheckBox.CheckedStates.Unchecked
TestAppSupportFolderDeleted = False

else
CB_TestApp_ApplicationSupport_TestAppfolder.State = CheckBox.CheckedStates.Checked
TestAppSupportFolderDeleted = True

end if

if plistDeleted and TestAppSupportFolderDeleted then
lblResult.TextColor = &c00800000
lblResult.text = “SUCCESS!”
else
dim mymessage as string
lblResult.TextColor = &cFF000000
if plistDeleted = False then
mymessage = "pList deletion failed. "
end if

if TestAppSupportFolderDeleted = False then
mymessage = mymessage + “TestApp folder deletion failed.”
end if

lblResult.text = mymessage

end if[/code]

and

[code]Public Function DeleteEntireFolder(theFolder as FolderItem, continueIfErrors as Boolean = false) as Integer
// Returns an error code if it fails, or zero if the folder was deleted successfully

dim returnCode, lastErr, itemCount as integer
dim files(), dirs() as FolderItem

if theFolder = nil or not theFolder.Exists() then
return 0
end if

// Collect the folder‘s contents first.
// This is faster than collecting them in reverse order and deleting them right away!
itemCount = theFolder.Count
for i as integer = 1 to itemCount
dim f as FolderItem
f = theFolder.TrueItem( i )
if f <> nil then
if f.Directory then
dirs.Append f
else
files.Append f
end if
end if
next

// Now delete the files
for each f as FolderItem in files
f.Delete
lastErr = f.LastErrorCode // Check if an error occurred
if lastErr <> 0 then
if continueIfErrors then
if returnCode = 0 then returnCode = lastErr
else
// Return the error code if any. This will cancel the deletion.
return lastErr
end if
end if
next

redim files(-1) // free the memory used by the files array before we enter recursion

// Now delete the directories
for each f as FolderItem in dirs
lastErr = DeleteEntireFolder( f, continueIfErrors )
if lastErr <> 0 then
if continueIfErrors then
if returnCode = 0 then returnCode = lastErr
else
// Return the error code if any. This will cancel the deletion.
return lastErr
end if
end if
next

if returnCode = 0 then
// We‘re done without error, so the folder should be empty and we can delete it.
theFolder.Delete
returnCode = theFolder.LastErrorCode
end if

return returnCode
End Function[/code]

@Markus Winter — The first error I see is that you assumed LastErrorCode is always positive, which is wrong:

If MyDeleteFile.LastErrorCode > 0 then

Docs say that “LastErrorCode may also return operating system-specific error codes if the error does not map to one of the above errors” and such errors are negative on macOS and possibly on other platforms.

I’ll try to get more into your post ASAP

@StphaneMons: Good catch - comes from trusting the Xojo documentation.

see https://documentation.xojo.com/api/files/folderitem.html.LastErrorCode

Don’t worry about it Stephane - something else came up and I won’t have time to look at this for a few days … I’ll get back to it next year