UnauthorizedAccessException

  • Thread starter Thread starter doug
  • Start date Start date
D

doug

I am getting this sporadically trying to delete files. It is hit and miss.
Sometimes the files delete correctly, sometimes they don't. Can anyone help
me figure out what the problem is?

Public Sub deleteCall(ByVal pCall As String)

Dim _log As New clsLog

Dim f As String

Try

Dim appWorkingDir As String =
Path.GetDirectoryName([Assembly].GetExecutingAssembly.GetName.CodeBase)

IO.File.Delete(appWorkingDir & "\Calls\C_" & pCall & ".xml")

IO.File.Delete(appWorkingDir & "\Calls\S_" & pCall & ".xml")

Dim files As String() = Directory.GetFiles(appWorkingDir & "\Calls\")

For Each f In files

_log.logEvent("Deleting file " & f)

If InStr(f, "_" & pCall & "_") > 0 Then IO.File.Delete(f)

Next f

Catch ex As Exception

_log.logEvent("*** error: " & ":" & ex.Message & ":" & ex.ToString)

End Try

End Sub
 
Back
Top