Trouble deleting the file

I’m having trouble deleting the file ver.dat in my code on OS X, I can not delete file.
what am I doing wrong?

Thank you,
Rui

this code does the following :

  • checks if I am connected to the internet
  • downloads the file
  • read the contents and verify the app version.

if System.Network.IsConnected then

    dim socket1 as new HTTPSocket
    check = new FolderItem("ver.dat")

    call socket1.get("http://www.xxx.pt/ver.dat", check, 3)

    e = getfolderitem("ver.dat")
    stream = e.openastextfile

    while not stream.eof
      checkvers = stream.readline
    wend

 if e <> nil and e.exists = true then
      
       if checkvers > vers then
        MsgBox("You have a new version avaiable.")
        e.Delete

       else

       e.Delete

       end if
  
 end if

socket1.Close

else
    
    msgbox("No network connection for you to do research.")

end if

You need to close the stream before attempting to delete the file it represents.

I was not focused on what I was doing.
Thank you Andrew