VB code to count the number of folders within a directory

  • Thread starter Thread starter pubdude2003 via AccessMonster.com
  • Start date 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!
 
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.
 
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
 
kewl, thanks Brandon, I'm about two code lines from what I want with that web
page link

THANKS!
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top