Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting accurate folder details

Posted on 2009-07-16
12
Medium Priority
?
392 Views
Last Modified: 2012-05-07
I have a script to read in a list of folders and for each one processed, try and retrieve the size of the folder, as well as number of files/folders contained therein (the exact results in a right-click property window on the folder would be ideal).

However, it seems using fso, I can't get accurate results.  One folder I'm testing against shows nearly 30mb with nearly 2000 files contained in over 300 folders.  My report shows the size (not the 'size on disk' - would love to have both), but only shows 3 folders and 0 for files...

Is there a reliable method to pull these details?
0
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24873117
Hi, SB.

Are you looping through all of the folders to get eh information or jsut reading the top level folder?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24873122
Geez, pardon all the typos.  My fingers and brain don't always talk to each other.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 24873887
Np - I've just been reading the top level.  I thought it 'had' worked in the past...now I'm not so sure... : (
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 76

Expert Comment

by:David Lee
ID: 24874438
I don't think there's a way to do this without iterating through the folders.  Even Explorer does that.  It does it a lot faster, but it still does it.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 24875092
Hmm - so I basically need some sort of counter for the files/folders then...  I think the size is actually correct for the entire folder though...
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1200 total points
ID: 24875190
Something like this will do it.
Dim objFSO, varFiles, varFolders, varSize
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
varFolders = -1
ProcessFolder objFSO.GetFolder("C:\SomeFolder")
Set objFSO = Nothing
'Code for doing something with the results goes here'
WScript.Quit
 
Sub ProcessFolder(objFolder)
    Dim objFile, objSubFolder
    For Each objFile In objFolder.Files
        varFiles = varFiles + 1
        varSize = varSize + objFile.Size
    Next
    varFolders = varFolders + 1
    For Each objSubFolder In objFolder.SubFolders
        ProcessFolder objSubFolder
    Next
    Set objFile = Nothing
    Set objSubFolder = Nothing
End Sub

Open in new window

0
 
LVL 10

Expert Comment

by:Alan_White
ID: 24876657
Yeah, the folder size works at top level (and very efficiently too) but if you want file count you have to trawl though each one.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 24881693
BDF - I'm off today, so I'll check this out on Monday.
Doesn't seem like I need to iterate the contents for size tho - I think that works fine as-is...this will still save me a bit of coding though - thanks.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24885847
No problem.  

If there's no need to total up the size, then we can modify the code and skip iterating the files.  That should speed this up a little.
Dim objFSO, varFiles, varFolders
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
varFolders = -1
ProcessFolder objFSO.GetFolder("C:\Users\David\Documents\Excel")
Set objFSO = Nothing
 
Sub ProcessFolder(objFolder)
    Dim objSubFolder
    varFiles = varFiles + objFolder.Files.count
    varFolders = varFolders + 1
    For Each objSubFolder In objFolder.SubFolders
        ProcessFolder objSubFolder
    Next
    Set objFile = Nothing
    Set objSubFolder = Nothing
End Sub

Open in new window

0
 
LVL 67

Author Comment

by:sirbounty
ID: 24913958
Sorry for the delay - running into some permission problems.
It's of course something that shouldn't be a problem, but for whatever reason, it occasionally is.
I hate to simply ignore those folders, so I'm presently working on something to find and correct the problem before processing the folder.
Whether I can or cannot get this working though, I'll close this out shortly, because it is giving me what I need on the 'working' folders.  Thanks!
0
 
LVL 67

Author Closing Comment

by:sirbounty
ID: 31604358
Thanks for the help!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24914922
No problem.  You're welcome!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question