Catch Catch ex As System.UnauthorizedAccessException

murrayf1

Member
Joined
May 5, 2006
Messages
21
Programming Experience
1-3
Hi im trying to catch an error
Catch ex As System.UnauthorizedAccessException but i cant seem to get it to work how do i do this?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

For Each filePath As String In IO.Directory.GetFiles("C:\", "*.ptf", IO.SearchOption.AllDirectories)
IO.File.Copy(filePath, "F:\" & IO.Path.GetFileName(filePath), True)

Try

Catch ex As System.UnauthorizedAccessException

End Try

Return
My.Application.Log.WriteEntry("An Error Occurred: " & e.ToString())




Next filePath
End Sub
 
In the FindFiles routine, inside of the For each F as as string in GetFiles use this maybe.

If f.ToLower.EndsWith("txt") then

now only files with extension .txt will get used. there are other ways but that's the method i used. If not good enough I have other solutions I have used as well. Lemme know :)

also use toupper or tolower b.c not all file extensions are upper or lower case.
 
Directory.GetFiles(Folder, Filter) where Filter can be for example "*.txt"
 
Back
Top