我想将目录的内容作为一个数组,不包括系统/隐藏文件和文件夹。 FileSystem.GetDirectories(path)
和FileSystem.GetFiles(path)
会返回路径中包含的所有文件。那么如何从中排除系统/隐藏文件呢?
答案 0 :(得分:1)
我知道这是一个老问题,但这里是解决方案!
FileSystem.GetFiles(path).Where(Function(file) ((file.Attributes And FileAttributes.Hidden) <> FileAttributes.Hidden) AndAlso (file.Attributes And FileAttributes.System) <> FileAttributes.System)
我刚刚根据你问的两个标志检查了所有文件。
答案 1 :(得分:0)
试试这个你必须修改linq查询或直接使用目录信息对象
Dim root As String = "X:\"
'Take a snapshot of the folder contents
Dim dir As New System.IO.DirectoryInfo(root)
Dim fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories)
' This query will produce the full path for all .txt files
' under the specified folder including subfolders.
' It orders the list according to the file name.
Dim fileQuery = From file In fileList _
Where file.Extension = ".txt" and file.Length >1645 _
Order By file.Length _
Select file