Directory.GetFiles question

  • Thread starter Thread starter Starbuck
  • Start date Start date
S

Starbuck

Hi

When the routine below is run it gets to the line - Dim fileEntries As
String() = Directory.GetFiles(tString) and then freezes, there is no errors
etc, the program just stops responding. The path is correct and does exist
and there is a test file in there
Any thoughts please?


Private Sub InboxTimer_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles InboxTimer.Tick
Try
Dim tString As String = gc.Inbox & "\"
Dim fileName As String = ""
InboxTimer.Enabled = False
Dim fileEntries As String() = Directory.GetFiles(tString)
For Each fileName In fileEntries
OpenInfile(fileName)
cf.Kill(fileName)
Next fileName
InboxTimer.Enabled = True
Catch ex As Exception
InboxTimer.Enabled = True
ErrorBox(ex.Message)
End Try
End Sub
 
Kevin,

That works just fine here. Are you seeing the problem when run in Relwase
mode as well? In addition, is there only one file in the folder, and it is a
folder on a local drive? Which value have you assigned to the Interval
property of the timer control?

I modified your code slightly. I know it's a matter of preference, but I
think it looks a little cleaner (no offence ;-)):

Try
InboxTimer.Enabled = False

' Is the backslash necessary?
Dim tString As String = gc.Inbox & "\"
Dim fileEntries() As String = Directory.GetFiles(tString)

' No need to declare your temp string variable previously,
' unless you use it elsewhere outside the loop
For Each fileName As String In fileEntries
OpenInfile(fileName)
cf.Kill(fileName)
Next
Catch ex As Exception
ErrorBox(ex.Message)
Finally
' This will always run, whether an exception is thrown or not.
InboxTimer.Enabled = True
End Try
 
Back
Top