请帮忙看哈这个代码!
以下代码是搜索摸个文件夹以及下一层文件内的文件数量,能否改成只统计某个文件内的文件夹名字,并保存。程序代码:
Dim searchingPath As String Dim pl As Long Dim finalOut As String Dim c As Long Private Sub cmdSave_Click() Open "c:\out.txt" For Output As #1 Print #1, finalOut Close #1 lblState.Caption = "保存完成! 已经写入到C:\Out.txt": DoEvents End Sub Private Sub cmdSearch_Click() c = 0 If Right(txtDirPath.Text, 1) <> "\" Then txtDirPath.Text = txtDirPath.Text + "\" pl = Len(txtDirPath.Text) SearchFile txtDirPath.Text End Sub Private Sub Form_Load() Me.Show txtDirPath.SetFocus txtDirPath.SelStart = Len(txtDirPath.Text) End Sub Private Sub txtDirPath_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then cmdSearch_Click End Sub Sub SearchFile(strPath As String) On Error Resume Next Dim strName As String Dim dir_i() As String Dim i As Long, idir As Long Dim showStr As String If Right(strPath, 1) <> "\" Then strPath = strPath + "\" strName = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly) Do While Len(strName) > 0 If strName <> "." And strName <> ".." Then If (GetAttr(strPath & strName) And vbDirectory) = vbDirectory Then idir = idir + 1 ReDim Preserve dir_i(idir) As String dir_i(idir - 1) = strName Else c = c + 1 showStr = Replace(Mid(strPath, pl + 1), "\", "><") finalOut = finalOut + "<" + Left(showStr, Len(showStr) - 1) + strName + vbCrLf End If End If strName = Dir If searchingPath <> strPath Then lblState.Caption = "索引数: " & CStr(c) & ",搜索目录: " & strPath searchingPath = strPath DoEvents End If Loop For i = 0 To idir - 1 Call SearchFile(strPath + dir_i(i)) Next i Erase dir_i lblState.Caption = "搜索完成,总计文件数: " & CStr(c) End Sub