我正在列出USB设备中的所有文件并进行自然搜索,例如下面的代码。我的问题是,当我尝试同时获取USB设备中的所有文件夹时,也正在获取System Volume Information文件夹时以及当我尝试访问IM获取时访问被拒绝错误。
实际上,我尝试“尝试捕获”,但这一次它带来了空列表。
通过这种方式在NFTS文件系统USB Device.FAT32上收到此错误。
Declare Unicode Function StrCmpLogicalW Lib "shlwapi.dll" (ByVal s1 As String, ByVal s2 As String) As Int32
Private Function CompareFiles(x As String, y As String) As Integer
Return StrCmpLogicalW(x, y)
End Function
For Each driver As DriveInfo In DriveInfo.GetDrives()
If driver.IsReady And driver.DriveType = DriveType.Removable Then
Dim ext = {"*.zip"}
Dim rootFiles() As String = ext.SelectMany(Function(f) Directory.GetFiles(driver.RootDirectory.ToString, f, SearchOption.TopDirectoryOnly)).OrderBy(Function(f) f).ToArray()
Array.Sort(rootFiles, New Comparison(Of String)(AddressOf CompareFiles))
'Next line gets System Volume Information
Dim otherFiles = ext.SelectMany(Function(f) Directory.GetFiles(driver.RootDirectory.ToString, f, SearchOption.AllDirectories)).OrderBy(Function(f) f).ToArray()
Array.Sort(otherFiles, New Comparison(Of String)(AddressOf CompareFiles))
ComBoxUsb.Items.Clear()
For Each model In rootFiles.Union(otherFiles)
ComBoxUsb.Items.Add(model)
Next
End If
Next