0

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

4

2 回答 2

0

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

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

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

于 2014-07-11T14:08:36.917 回答
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
于 2013-01-15T17:08:04.597 回答