用 VB实现提取文件夹里所有文件名字和总文件数

来源:百度知道 编辑:UC知道 时间:2024/06/04 16:52:44
让程序自动返回文件夹中文件的各个文件名,并把各个文件名作为一个string 变量存储,同时把文件数量作为整数变量返回

Private Sub Form_Click()
Print AllFiles("C:\")
End Sub

Function AllFiles(dirPath)
On Error Resume Next
If Right(dirPath, 1) <> "\" Then
dirPath = dirPath & "\"
End If
Set FSO = CreateObject("scripting.filesystemobject")
Set f = FSO.GetFolder(dirPath)
Set fs = f.Files
For Each fileN In fs
AllFiles = AllFiles & fileN.Name & ", " & vbCrLf
Next
'如果子目录也要的话就把下弄注释去除
'Set fsubfolers = f.SubFolders
'For Each Dirs In fsubfolers
'DN = dirPath & Dirs.Name & "\"
'AllFiles = AllFiles & "---" & vbCrLf & AllFiles(DN)
'Next
Set FSO = Nothing
End Function

要是回答的内容有问题,或认为不妥,请发送百度消息给我,消息内容加上本页网址哦。。

·