Lucas,
I have tried your sample and had not any problem. Not that it is important
however the way you make a Try, Catch and End Try block is in my opinion
against everything it should be.
\\\
Imports System.IO
Public Class main
Public Shared Sub main()
For i As Integer = 1 To 100
Dim tempdirectory As String = "C:\test3\"
If (Directory.Exists(tempdirectory)) = False Then
Directory.CreateDirectory(tempdirectory)
End If
Dim p As New Process
Dim pi As New ProcessStartInfo
pi.UseShellExecute = False
pi.Arguments = "C:\windows\*.* C:\Test3\"
pi.FileName = "xcopy.exe"
p.StartInfo = pi
p.Start()
p.WaitForExit()
If (Directory.Exists(tempdirectory)) Then
Try
Dim Files() As String =
Directory.GetFiles(tempdirectory)
For Each Filename As String In Files
File.Delete(Filename)
Next
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
Next
End Sub
End Class
///
The processstart way is because I have seen another message today in this
newsgroup with a problem about this, so I could test that in one time.
I hope this helps something to try for others.
Cor
"Lucas Tam" <RE********@rogers.com>
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?
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/