VB code to count the number of folders within a directory

  • Thread starter pubdude2003 via AccessMonster.com
  • Start date
P

pubdude2003 via AccessMonster.com

I would like to write a bit of code into a form that counts the number of
folders in the "D:/1"directory like "* - Done" and like "*". I have found
lots of code that counts files but none that count the folders they reside in.


Can anyone suggest anything?

Thanks!
 
B

Brandon Johnson

I would like to write a bit of code into a form that counts the number of
folders in the "D:/1"directory like "* - Done" and like "*". I have found
lots of code that counts files but none that count the folders they reside in.

Can anyone suggest anything?

Thanks!

Dim temp As Folders, names As Integer
Dim oFileSystem As New FileSystemObject
Set temp = oFileSystem.GetFolder(textbox1)
names = temp.Count

try that. i havent tested it at all.
 
B

Brandon Johnson

I would like to write a bit of code into a form that counts the number of
folders in the "D:/1"directory like "* - Done" and like "*". I have found
lots of code that counts files but none that count the folders they reside in.

Can anyone suggest anything?

Thanks!

or even look at this site...
http://abstractvb.com/code.asp?A=716
 
P

pubdude2003 via AccessMonster.com

kewl, thanks Brandon, I'm about two code lines from what I want with that web
page link

THANKS!
 
P

pubdude2003 via AccessMonster.com

well maybe not two

Private Sub Command1_Click()
FilesInFolder ("D:/1/")
End Sub

Function FilesInFolder(folderspec) As Long

Dim objFSO As Object
Dim objFolder As Object
Dim filesinfolder2 As Long
Dim datnumber As Integer

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(folderspec)
Set oFS = CreateObject("Scripting.FileSystemObject")

Set oF = oFS.GetFolder(folderspec)

Me!Text10 = oF.subfolders.Count

Set objFolder = Nothing
Set objFSO = Nothing
End Function
 
Top