艾诺迪亚4二周目剧情:如何用VB中的DIR函数查找某个属性的文件???

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 02:01:27
我想用VB查找计算机中具有某个属性的文件和快捷方式,请指教
或者能够判断出一个已知文件的属性也可以

Public Function TreeSearch(ByVal sPath As String, ByVal sFileSpec As String, sFiles() As String) As Long
Static lFiles As Long
Dim sDir As String
Dim sSubDirs() As String
Dim lIndex As Long
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
sDir = Dir(sPath & sFileSpec)

Do While Len(sDir)
lFiles = lFiles + 1
ReDim Preserve sFiles(1 To lFiles)
sFiles(lFiles) = sPath & sDir
sDir = Dir
Loop

lIndex = 0
sDir = Dir(sPath & "*.*", 16)
Do While Len(sDir)
If Left(sDir, 1) <> "." Then

If GetAttr(sPath & sDir) And vbDirectory Then
lIndex = lIndex + 1

ReDim Preserve sSubDirs(1 To lIndex)
sSubDirs(lIndex) = sPath & sDir & "\"
End If
End If
sDir = Dir
Loop
For lIndex = 1 To lIndex

Call TreeSearch(sSubDirs(lIndex), sFileSpec, sFiles())
Next lIndex
TreeSearch = lFiles
End Function

用Dir枚举
再用Open打开
用FileAttr就可以获得其属性
判断一下即可

树的层次遍历问题
要用一个队列完成,楼上用了动态数组,用Collection类也可以,不会的话就用列表框控件当队列