FolderItem Returning a 101 on Delete, but f.exists is true?

Hi Folks,

I’m working on a refactored version of some file handling and I’ve running into and oddity. When I call f.Delete after getting the FolderItem, I’m getting a 101 as the LastErrorCode. If f.Exists, how could f.Delete result in a 101?

Here’s the code:

Dim f As FolderItem Dim x As Integer // the LoadedDefinition is derived from the list item selected in the ContextualMenu click // BRUDefinitionPath is a Nativepath string with a trailing / or \\ depending on the platform f = GetFolderItem(BRUDefinitionPath + LoadedDefinition, FolderItem.PathTypeNative) If f <> Nil And f.Exists Then // <-- if this is correct, then ... Dim md As New MessageDialog md.Title = "Job Deletion" md.Message = "Delete selected job?" md.explanation = "This will delete the job specfications from your environment. " + _ It will NOT remove any other data associated with previous runs of this job" + _ EndOfLine + EndOfLine + "Delete Job """ + LoadedDefinition + """?" md.ActionButton.Caption = "Delete" md.CancelButton.Visible = True md.CancelButton.Default = True md.CancelButton.Caption = "Keep" If md.ShowModalWithin(WMain) = md.ActionButton Then f.Delete // <-- I should never get here, right? If f.LastErrorCode <> 0 Then Break End If Me.RemoveRow(Me.ListIndex) For x = JobDefinitions.Ubound DownTo 0 If JobDefinitions(x) = LoadedDefinition Then JobDefinitions.Remove(x) End If Next End If End If

  f.Delete //                            <-- I should never get here, right?
    If f.LastErrorCode <> 0 Then
      Break //<--- you actually mean here?
    End If

you mean you should never get to the BREAK, not the DELETE line, right?
since you wouldn’t “expect” an error when deleting an existing file…

if the file to be deleted a local or remote file? (not that it really should matter)

or as suggested on another thread… is the file still OPEN?

Tim,

Have a look at the couple of replies i posted in my other thread.

Also, you could put something like:

Msgbox(f.NativePath)

or

Msgbox(f.DisplayName)

just before your f.Delete

And see what that shows you…

Thanks, but I’ve stepped through this in the debugger and watched the Exists property show as True before the Delete call. Of course, it doesn’t exist “after” the Delete call since the file no longer exists, but the LastErrorCode should not show 101 if the call was to Delete. Otherwise, the 101 would indicate success with regard to the Delete call. Maybe that is the issue and 101 is valid after a call to Delete.

Try to see if file exists before delete command in your code and see what you will get as reply.

?f.Exists

Also you can update your code regarding to using break with bellow way as any fair suggestion


    If f.LastErrorCode = 0 Then

      Me.RemoveRow(Me.ListIndex)

      For x = JobDefinitions.Ubound DownTo 0
            If JobDefinitions(x) = LoadedDefinition Then
                  JobDefinitions.Remove(x)
            End If
      Next

    End If

Also you can set in ELSE part error message and display error - later when you fix issue.

[quote=393380:@Dave S] f.Delete // <-- I should never get here, right? If f.LastErrorCode <> 0 Then Break //<--- you actually mean here? End If
you mean you should never get to the BREAK, not the DELETE line, right?
since you wouldn’t “expect” an error when deleting an existing file…

if the file to be deleted a local or remote file? (not that it really should matter)

or as suggested on another thread… is the file still OPEN?[/quote]

No - since the f <> Nil And f.Exists should be False when that check is made, I should never get into the part of the loop that allows the f.Delete call to occur.

The files are in a local folder and both the folder and the file are there with proper permissions.

As mentioned above, I’m getting a 101, not a 102, 103, or 104. Maybe that’s the thing here. Since I’m deleting the file (which is deleted successfully, BTW), maybe the return of 101 is a validation of the Delete call instead of a 0?

  1. double check current location which is in use for storing files and files on that location since maybe file already exists…

  2. try to remove f<> nil and put only f.exists… if is nil then you will get error which you can catch and then know that is nil :wink: