We help IT Professionals succeed at work.
Get Started

VB App won't populate ListBox with files found with GetFiles

Jason Paradis
Last Modified: 2017-11-27
Private Sub findPSTButton_Click(sender As Object, e As EventArgs) Handles findPSTButton.Click
        BackupperProgress.Value = 0
            For Each foundPST As String In My.Computer.FileSystem.GetFiles(
                Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), Microsoft.VisualBasic.FileIO.SearchOption.SearchAllSubDirectories, "*.pst")
        Catch ex As Exception

        End Try
        BackupperProgress.Value = 99
    End Sub

Open in new window

According to several sources, this should do the following:

a) Start the progress bar
b) Search the current logged in User Profile folder for PST files.
c) Ignore Junction Points (i.e. My Pictures under Documents, etc) and all exceptions
d) Add all of the PST's found to the ListBox

Unfortunately, when the button is clicked nothing appears in the list box. Can anyone tell me what I've done wrong here?

EDIT: By adding a MsgBox(ex.Message) I found out that I'm still getting access denied errors. I've tried putting a Catch line after the For Each one but it blocks the foundPST variable from being used elsewhere in the code. It also says that a Next line needs to be before the Catch. But if I do that I'm back to square one.
Watch Question
Analyst Assistant
Distinguished Expert 2020
This problem has been solved!
Unlock 2 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE