title: Unhide all hidden files, folders, subfolders and subfiles except access denied path using Visual Basic
body: <p>My code below albe to Unhide all hidden files, folders, subfolders and subfiles. The problem is it'll stop if any access denied path. How to make the code skip access denied path and continue with other paths.</p>
  
  <pre><code>Dim MyDrive As String = "D:\"
  Dim FileCounter As Integer = 0
  Dim FolderCounter As Integer = 0
  Dim DriveObj As New IO.DirectoryInfo(MyDrive)
  
  Dim Files As IO.FileInfo() = DriveObj.GetFiles("*.*", IO.SearchOption.AllDirectories)
  Dim Directories As IO.DirectoryInfo() = DriveObj.GetDirectories("*.*", IO.SearchOption.AllDirectories)
  
      Dim Filename As IO.FileSystemInfo
          For Each Filename In Files
              On Error Resume Next
              If (IO.File.GetAttributes(Filename.FullName) And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then
                  ' Show the file.
                  IO.File.SetAttributes(Filename.FullName, IO.FileAttributes.Normal)
                  FileCounter = FileCounter + 1
              End If
          Next
  
          Dim DirectoryName As IO.DirectoryInfo
          For Each DirectoryName In Directories
              On Error Resume Next
              If (IO.File.GetAttributes(DirectoryName.FullName) And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then
                  ' Show the folder.
                  IO.File.SetAttributes(DirectoryName.FullName, IO.FileAttributes.Normal)
                  FolderCounter = FolderCounter + 1
              End If
          Next
  </code></pre>