【发布时间】:2013-04-07 19:29:35
【问题描述】:
我正在制作一个文件夹列表,其中每个文件夹只需要几个属性,所以我使用下面的类。但是,无论是哪个文件夹,FilesInFolder 属性总是比文件夹中的实际文件数多 5 个。
有人可以帮我找出问题所在吗?谢谢。
Public Class Single_Action_Folder
Public ReadOnly FullName As String = ""
Public ReadOnly Name As String = ""
Public ReadOnly FilesInFolder As Integer = 0
Public ReadOnly Exists As Boolean = False
'**
' Constructor
'*
Public Sub New(Optional dir As DirectoryInfo = Nothing)
' First check that a directory has been specified
If dir Is Nothing Then Exit Sub
' Populate the class properties
FullName = dir.FullName
Name = dir.Name
FilesInFolder = dir.GetFiles().Count
Exists = dir.Exists
End Sub
End Class
【问题讨论】:
-
@Belial09:该链接与 OP 已经尝试过的链接有何不同?
-
您是否查看了 GetFiles 枚举返回的文件?
-
@Tim Schmelter 如果您查看帖子中的其他答案,则有一个 LINQ 解决方案。链接上的答案不同,因为在 GetFiles() 函数中输入了参数。
-
@Belial09:但是,他想要一个目录中的总文件数,所以我不明白为什么使用搜索模式或搜索选项会有所帮助。
dir.GetFiles().Count()应该可以工作。