0

I am just writing a simple file browser. It works without problems when i point to a specific directory but throws "UnauthorizedAccessException access to the path .... is denied" when i point to drive "C:\\" or "D:\\" appreciate any help.

If Not txtToSearch.Text = Nothing Then
            ListBox1.Items.Clear()
            FC = 0
            For Each foundfile As String In My.Computer.FileSystem.GetFiles("D:\\", FileIO.SearchOption.SearchAllSubDirectories, Nothing)
                Dim title As String = My.Computer.FileSystem.GetFileInfo(foundfile).Name
                If title.Contains(txtToSearch.Text) Then
                    ListBox1.Items.Add(title)
                    FC += 1
                End If
            Next
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by lolafuertes
0

yes i tried both of them and got the exception in that case.

0

Ok.
The error generated by GetFiles, comes from a folder that you do not have enough privileges to read all the contents.

In the exception, you have the offending folder (ie: on Vista, "Access to the path 'C:\Documents and Settings' is denied".)

As this can happen in many others folders, I would suggest not to get all the file names in the drive with only one sentence.

Moreover, if you count the files and folder in the drive, you can get a lot of thousands, so this can be unmanageable in a listbox.

Hope this helps

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.