如何在vb.net中获取目录内容而不包含系统/隐藏文件?
我想以数组的形式获取目录的内容,不包括系统/隐藏文件和文件夹如何在vb.net中获取目录内容而不包含系统/隐藏文件?,vb.net,file,Vb.net,File,我想以数组的形式获取目录的内容,不包括系统/隐藏文件和文件夹FileSystem.GetDirectories(path)和FileSystem.GetFiles(path)返回路径中包含的所有文件。那么如何从中排除系统/隐藏文件呢?试试看,您必须修改linq查询或直接使用目录信息对象 Dim root As String = "X:\" 'Take a snapshot of the folder contents Dim dir As New Syste
FileSystem.GetDirectories(path)
和FileSystem.GetFiles(path)
返回路径中包含的所有文件。那么如何从中排除系统/隐藏文件呢?试试看,您必须修改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
我知道这是一个老问题,但这里有解决办法
FileSystem.GetFiles(path).Where(Function(file) ((file.Attributes And FileAttributes.Hidden) <> FileAttributes.Hidden) AndAlso (file.Attributes And FileAttributes.System) <> FileAttributes.System)
FileSystem.GetFiles(path).Where(函数(file)((file.Attributes和FileAttributes.Hidden)FileAttributes.Hidden)和also(file.Attributes和FileAttributes.System)FileAttributes.System)
我只是根据您要求的两个标志检查了所有文件。这些函数上没有可直接执行此操作的选项。您可能需要获取每个条目的
FileInfo
,看看它是否是系统文件。这就是我现在正在做的,我想会有更好的方法。谢谢你的评论。你能解释一下吗?我不想列出所有的txt文件。