我想在目录计算机中显示搜索隐藏文件/文件夹的结果。 在命令提示符下命令显示文件/文件夹,如下所示 " shell(" dir / ah")"。
现在我有问题了吗?我怎样才能将这些代码发送到vb.net,结果显示在listboxt vb.net中?
答案 0 :(得分:1)
Dim directory As New DirectoryInfo("D:\Apps\Hidden")
Dim hidden_Files As FileInfo() = directory.GetFiles(). _
Where(Function(file) (file.Attributes And FileAttributes.Hidden) <> 0).ToArray()
Dim hidden_folders As DirectoryInfo() = directory.GetDirectories(). _
Where(Function(dirs) (dirs.Attributes And FileAttributes.Hidden) <> 0).ToArray()
您可以将它们添加到ListBox
控件中,如下所示(您可以使用逻辑代替此):
lstHiddenItems.Items().Add("--FILES--")
For Each itm In hidden_Files
lstHiddenItems.Items.Add(itm.Name)
Next
lstHiddenItems.Items().Add("")
lstHiddenItems.Items().Add("--FOLDERS--")
For Each itm In hidden_folders
lstHiddenItems.Items.Add(itm.Name)
Next
结果
答案 1 :(得分:0)
遍历给定路径中的每个文件。如果它具有隐藏属性,则将其添加到列表中。最后将它分配给ListBox的数据源
Dim myHiddenFileList As List(Of String) = New List(Of String)()
Dim thePath As String = "Some Directory Path"
' Iterate through file in directory thePath
For Each f In My.Computer.FileSystem.GetFiles(thePath)
Dim fileAttributes As FileAttributes = My.Computer.FileSystem.GetFileInfo(f).Attributes
If Not fileAttributes Is Nothing AndAlso fileAttributes = FileAttributes.Hidden Then
myHiddenFileList.Add(f) ' It is hidden so add to the list
End If
Next
myListBox.DataSource = myHiddenFileList ' myListBox is a list box already defined on the form.