Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Folder File count

Status
Not open for further replies.

johnmtb

Programmer
Jul 12, 2008
37
US
Dear All,

I need to know how many files there are in a particular folder. The following code works, but considering that, f.DateCreated, f.Size and f.Type, all provide the information I need. But f. FolderContents, f.Contents, and several others I tried do not work.

Code:
Sub ShowFolderInfo(folderspec)

Dim fs, f, f1, fc, s, t, u, v
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
s = f.DateCreated
t = f.Size
u = f.Type
'v = f.FolderContents
x = 0
For Each f1 In fc
     v = f1.Name
     x = x + 1
Next

End Sub

As I said this code works, but it is ugly. If anyone knows what I have to add to f. to provide me with the number of files in the folder, I shall be very grateful.

Regards,

john
 
Your f variable represents a Scripting.Folder object. As such, you can return the number of files in the folder with"

[tt][blue]f.Files.Count[/blue][/tt]

You can also get the number of subfolders with....

[tt][blue]f.SubFolders.Count[/blue][/tt]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Disferente,

i am afraid your suggestion did not work.

but thank you all the same.

regards,

john
 
gmmastros,

thank you, that suggestion worked.

regards,

john
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top