1
我的代碼如下,以取消隱藏所有隱藏的文件,文件夾,子文件夾和子文件。問題是,如果任何訪問被拒絕,路徑會停止。如何使代碼跳過訪問被拒絕的路徑並繼續其他路徑。使用Visual Basic取消隱藏除訪問被拒絕路徑之外的所有隱藏文件,文件夾,子文件夾和子文件
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
直視的try/catch http://msdn.microsoft.com/en-us/library/fk6t46tz.aspx – Plutonix