Here is some code that should work but doesn't.. And this is the 3rd iteration of the code (it is the cleanest that remains). The other versions I have beat on so much they don't look like reasonable code anymore.
the goal of the method is to delete a folderitem. If the said folderitem is a directory, it will delete the contents prior to deleting itself. As folderitem.delete won't delete itself and all subdirectories/files.
Sub deleteFolderitem(deleteItem as folderitem) if deleteItem = NIL then return // cant delete a NIL folderitem if not deleteItem.Exists then return // it doesnt exist so we cant delete it. if deleteitem.Directory then // its a directory/folder if deleteItem.Count > 0 then // we have subfolders and/or files in the directory that we need to delete first // going to use MBS plugins for getting the list of files(filesMBS) and directories(folderMBS) for each oFile as folderitem in deleteItem.FilesMBS oFile.delete if oFile.LastErrorCode > 0 then // we have an error on the file delete System.DebugLog "oFile.LastErrorCode = " + cstr( oFile.LastErrorCode ) + " for " + oFile.ShellPath end if next // no the directories for each oDir as folderitem in deleteItem.FoldersMBS // call myself(the method) recurisively to get the subdirectory clear. deleteFolderitem( oDir ) // now that we are in theory empty we can delete the directory. oDir.delete if oDir.LastErrorCode > 0 then // we have an error on the file delete System.DebugLog "oDir.LastErrorCode = " + cstr( oDir.LastErrorCode ) + " for " + oDir.ShellPath end if next end if deleteItem.delete if deleteItem.LastErrorCode > 0 then // we have an error on the directory delete System.DebugLog "deleteItem.LastErrorCode = " + cstr( deleteItem.LastErrorCode ) + " for " + deleteItem.ShellPath end if else // its a file deleteItem.delete if deleteItem.LastErrorCode > 0 then // we have an error on the file delete System.DebugLog "deleteItem.LastErrorCode = " + cstr( deleteItem.LastErrorCode ) + " for " + deleteItem.ShellPath end if end if End Sub
thanks... I know that I am doing something stupid.