简体   繁体   English

如何在vb.net中不包含系统/隐藏文件的情况下获取目录内容?

[英]How to get contents of a directory without including system/hidden files in vb.net?

I want to get the contents of a directory as an array excluding system / hidden files and folders. 我想获取目录的内容作为不包括系统/隐藏文件和文件夹的数组。 FileSystem.GetDirectories(path) and FileSystem.GetFiles(path) returns all files included in the path. FileSystem.GetDirectories(path)FileSystem.GetFiles(path)返回该路径中包含的所有文件。 So how to exclude system/hidden files from it? 那么如何从中排除系统/隐藏文件呢?

I know it's an old question but here the solution! 我知道这是一个老问题,但是这里有解决方案!

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

I just checked all files against the two flags you asked. 我只是对照您要求的两个标志检查了所有文件。

Try this you will have to modify the linq query or just use the Directory Info Object Directly 尝试此操作,您将必须修改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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM