I cannot delete a file (FolderItem.Delete)

The code below is meant to allow me to unlock and delete a file I choose from a list. Unfortunately, the file is not unlocked and I get an error 101.

[code] Dim DelFI As FolderItem

DelFI = GetOpenFolderItem("")
If DelFI = Nil Then
MsgBox “Unable to locate the target file.”
Return
End If

TA.SelText = DelFI.NativePath + EndOfLine
If DelFI.Locked Then
TA.SelText = “DelFI.Locked is locked.”
Else
TA.SelText = “DelFI.Locked is NOT locked.”
End If

DelFI.Locked = False
If DelFI.LastErrorCode > 0 then
MsgBox “An error occured” + EndOfLine + EndOfLine + "[Locked] Unable to unlock the file. Error " + Str(DelFI.LastErrorCode)
Return
Else
MsgBox “File was unlocked”
End if

// (try to) Delete the selected file
DelFI.Delete()
If DelFI.LastErrorCode > 0 then
MsgBox “An error occured” + EndOfLine + EndOfLine + "[Delete] Unable to delete the file. Error " + Str(DelFI.LastErrorCode)

Else
MsgBox “File deleted!”
End if[/code]

This code is in a PushButton, TA is a TextArea for temporary debug reports… it will be used later for different things.

Is there something wrong ?

Do you have permissions to unlock the file? If you don’t have permission to make that change, Xojo can’t either.

Hi Tim and thanks for the answer.

Yes, I think at that and selected a file beside my application that is in the project folder, not in a protected area of the internal hard disk.

Nota: I started by trying to do the job in a file located in the User Library / Preferences folder and migrated the idea for debug purposes there.

BTW: when the Finder is not in the mood to let me delete an item from one of the protected folder, it issue a warning message and ask me in a different dialog for tha Administrator password. Nothing here.

Other idea ?

BTW: Tim, were you awoke early today ?

I was awake early for my day job.
If Finder is asking for a password then Xojo will not be able to unlock it without authentication.

Look into how Xojo might be able to get administrator authentication. I’d be more helpful but I’m on mobile right now.

[quote=180371:@Tim Parnell]I was awake early for my day job.
If Finder is asking for a password then Xojo will not be able to unlock it without authentication.

Look into how Xojo might be able to get administrator authentication. I’d be more helpful but I’m on mobile right now.[/quote]

He is trying to delete a file in the Applications folder, where entering the administrator’s password is mandatory to delete, move or modify a file… I do not think Xojo can do anything.

No I am not, actually. At first I wanted to do that in the UserLibrary folder and since it does not worked (to unlock a file there, a fil I locked), I try now to know if f.Locked = False works.

Thanks for trying.

Incredible: very late at night, I awoke and powered on Xojo (took the LR code, add a bit more lines) to discover:

[code]Function MouseDown(X As Integer, Y As Integer) As Boolean
dim f as New folderitem
f=GetOpenFolderItem(“text/plain”)

if f.locked then
MsgBox “the file is locked! I will unlock it.”
f.Locked = False
else
//access the file
MsgBox “the file is unlocked! I will lock it.”
f.Locked = True
end if
End Function[/code]

Works just as expected. Now I have a base fo work (the not functioning code may be because of something else and booting directly to Xojo let the one above works ?).