繁体   English   中英

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

[英]How to get contents of a directory without including system/hidden files in 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

暂无
暂无

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

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