如何获取目录的内容,而不包括vb.net中的系统/隐藏文件



我想获得一个目录的内容作为一个数组,不包括系统/隐藏文件和文件夹。FileSystem.GetDirectories(path)FileSystem.GetFiles(path)返回路径中包含的所有文件。那么如何从它排除系统/隐藏文件?

我知道这是一个老问题,但这里的解决方案!

FileSystem.GetFiles(path).Where(Function(file) ((file.Attributes And FileAttributes.Hidden) <> FileAttributes.Hidden) AndAlso (file.Attributes And FileAttributes.System) <> FileAttributes.System)

我刚刚根据你要求的两个标志检查了所有文件

尝试这样做,您将不得不修改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

最新更新