I have a service that runs on a server waiting for files with a certain extension to arrive and then process them. It was written in VB .NET 2003 using the .NET 1.1 Framework and I want to update it to VB .NET 2005 and the .NET Framework 2.0 (or 3.0 but it makes no difference).

One of the things this service needs to do is to process any existing files when it starts up. in the .NET 1.1 version it does this by recursively itererating through the folders on a drive and extracting the names of the files therein. Works like a charm.

When doing the conversion to .NET 2.0, I came across the IO.DirectoryInfo.GetFiles method that seemed to make life easier for me (no more recursive directory porcessing) as I thought I could use some code like to retrieve all the existing files.

Dim files() As IO.FileInfo

Dim di As New IO.DirectoryInfo("c:")

files = di.GetFiles(filepattern, IO.SearchOption.AllDirectories)

I was wrong. Everything works like clockwork until the method hits the System Volume Information folder. It then aborts with an UnauthorizedAccessException error as can be seen below. In the .NET 1.1 version I ignore any folders with the System attribute set.

System.UnauthorizedAccessException was unhandled
Message="Access to the path 'c:System Volume Information' is denied."

Handling the error in a Try ... Catch block is not an answer either as yes, this catches the error and you can handle it. (What you will do with it I'm not sure), but execution stops there.

Does anybody know a way around this? I have looked in the MSDN to no avail. I have a feeling there is no way around this problem until Microsoft add a parameter something like IgnoreSystemFolders to the GetFiles method.

I know I can get around this by using my original method of recursing through the folders but life would have been so much easier if only ............

Anyway, all help will be gratefully taken.

I thank you all in advance.


Kevin Bell