L
Lucas Tam
I have a very simple loop:
If (Directory.Exists(tempDirectory)) Then
Try
Dim Files() As String = Directory.GetFiles(tempDirectory)
'Clear out directory
For Each Filename As String In Files
File.Delete(Filename)
Next
Catch ex As Exception
End Try
End If
The first file will delete fine, but the second file will raise a
UnauthorizedAccessException.
To solve the problem, I added a Thread.Sleep(1000) after the File.Delete.
Anyone notice that if you delete stuff too quickly, .NET will raise a
UnauthorizedAccessException? Is there a way to continue after previous
delete is completed?
If (Directory.Exists(tempDirectory)) Then
Try
Dim Files() As String = Directory.GetFiles(tempDirectory)
'Clear out directory
For Each Filename As String In Files
File.Delete(Filename)
Next
Catch ex As Exception
End Try
End If
The first file will delete fine, but the second file will raise a
UnauthorizedAccessException.
To solve the problem, I added a Thread.Sleep(1000) after the File.Delete.
Anyone notice that if you delete stuff too quickly, .NET will raise a
UnauthorizedAccessException? Is there a way to continue after previous
delete is completed?