I want get count of files and folders exist in CD very fast, Like windows in my computer in propertise of each folder.
for sample "Cd contain : 25 Folders,120 Files"
Printable View
I want get count of files and folders exist in CD very fast, Like windows in my computer in propertise of each folder.
for sample "Cd contain : 25 Folders,120 Files"
All you need is:Code:Option Explicit
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Text1.Text = File1.ListCount
End Sub
Private Sub Form_Load()
On Error Resume Next
Drive1.Path = "D:"
End Sub
DirListBox called Dir1
FileListBox called File1
TextBox called Text1
and use that code :) It is simple and not the best way but it does work.
no.I want count of all subfolders and files
Use FileSystemObject.
Code:Option Explicit
Private Sub Form_Load()
Dim DirsCount As Long, FilesCount As Long
DirList "C:\", DirsCount, FilesCount
MsgBox FilesCount & " Files, " & DirsCount & " Folders"
End Sub
Private Sub DirList(ByVal Root As String, DirsCount As Long, FilesCount As Long)
Dim sDir As String
Dim Dirs As New Collection
If Right(Root, 1) <> "\" Then Root = Root & "\"
On Error Resume Next
sDir = Dir(Root & "*", vbArchive + vbDirectory + vbHidden + vbReadOnly + vbSystem)
Do Until Len(sDir) = 0
If sDir <> "." And sDir <> ".." Then
If (GetAttr(Root & sDir) And vbDirectory) = vbDirectory Then
If Err.Number = 0 Then
Dirs.Add sDir
DirsCount = DirsCount + 1
Else
FilesCount = FilesCount + 1
Err.Clear
End If
Else
FilesCount = FilesCount + 1
End If
End If
sDir = Dir
Loop
Do Until Dirs.Count = 0
DirList Root & Dirs(1), DirsCount, FilesCount
Dirs.Remove 1
Loop
End Sub