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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Folder depth and child-folder counter

Status
Not open for further replies.

ChrisMo3142

Technical User
Oct 12, 2010
3
GB
thread329-954944

Hi,

I used the script following script:-
=======================================
Dim oFS, oFolder
Dim objexcel, r, lnameArray, lname, nameLength
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFolder = oFS.GetFolder("\\BZN1\rootfs\mohammedc429\Group\EUNBZN\BZNMS007_501 Sqn")

Set objExcel = createobject("Excel.application")
objexcel.Workbooks.add
objexcel.Cells(1, 1).Value = "Folder Name"
objexcel.Cells(1, 2).Value = "Size (MB)"
objexcel.Cells(1, 3).Value = "# Files"
objexcel.Cells(1, 4).Value = "# Sub Folders"
objexcel.Visible = True
Wscript.Sleep 300
r=2


ShowFolderDetails oFolder, r



' objexcel.ActiveWorkbook.SaveAs("\\BZN1\rootfs\mohammedc429\Personal\counts\LogonReport.xls")
' objexcel.Quit
MsgBox "Done"

Function ShowFolderDetails(oF,r)
Dim F
objexcel.Cells(r, 1).Value = oF.Name
objexcel.Cells(r, 2).Value = oF.Size /1024\1024
objexcel.Cells(r, 3).Value = oF.Files.Count
objexcel.Cells(r, 4).Value = oF.Subfolders.count
r = r+1
for each F in oF.Subfolders
ShowFolderDetails F, r
next
End Function
============================================
What I was looking for is a way to adapt this to not only count all child-folders but, also to display each level depth in Excel.

E.g. if this path existed C:\test\test1\test2\test3\test4

I would like the results to be listed in columns listed by depth, level 1 has test, level 2 has test1 etc...

Any help is much appreciated!!

Chris.
 
Basically

objexcel.Cells(r, 5).Value = r

Although the initial value of r (r=2) will have an impact

 
ok, bearing in mind that I am a VBScript biff....How do I add that into my current script....Sorry to be a pain :-(
 
objexcel.Cells(r, r + 1).Value = oF.Name
objexcel.Cells(r, r + 2).Value = oF.Size /1024\1024
objexcel.Cells(r, r + 3).Value = oF.Files.Count
objexcel.Cells(r, r + 4).Value = oF.Subfolders.count

???
 
So ...


Function ShowFolderDetails(oF,r)
Dim F
Static Depth

Depth=Depth+1
objexcel.Cells(r, 1).Value = oF.Name
objexcel.Cells(r, 2).Value = oF.Size /1024\1024
objexcel.Cells(r, 3).Value = oF.Files.Count
objexcel.Cells(r, 4).Value = oF.Subfolders.count
objexcel.Cells(r, 5).Value = Depth
r = r+1
for each F in oF.Subfolders
ShowFolderDetails F, r
next
Depth=Depth-1
End Function
 
thanks strongm, i knew something wasnt quite right with just the use of r
 
thanks for the help so far guys, much appreciated!

So, the script looks like this:-
=======================================
Dim oFS, oFolder
Dim objexcel, r, lnameArray, lname, nameLength
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
set oFolder = oFS.GetFolder("\\BZN1\rootfs\mohammedc429\Group\EUNBZN\BZNMS007_501 Sqn")
Set objExcel = createobject("Excel.application")
objexcel.Workbooks.add
objexcel.Cells(1, 1).Value = "Folder Name"
objexcel.Cells(1, 2).Value = "Size (MB)"
objexcel.Cells(1, 3).Value = "# Files"
objexcel.Cells(1, 4).Value = "# Sub Folders"
objexcel.Visible = True
Wscript.Sleep 300
r=2
ShowFolderDetails oFolder, r
' objexcel.ActiveWorkbook.SaveAs("\\BZN1\rootfs\mohammedc429\Personal\counts\LogonReport.xls")
' objexcel.Quit
MsgBox "Done"

Function ShowFolderDetails(oF,r)
Dim F
Static Depth
Depth=Depth+1
objexcel.Cells(r, 1).Value = oF.Name
objexcel.Cells(r, 2).Value = oF.Size /1024\1024
objexcel.Cells(r, 3).Value = oF.Files.Count
objexcel.Cells(r, 4).Value = oF.Subfolders.count
objexcel.Cells(r, 5).Value = Depth
r = r+1
for each F in oF.Subfolders
ShowFolderDetails F, r
next
Depth=Depth-1
End Function
=======================================
I get an error pointing to line 21 (Static Depth), char 5...Expected statement. Code 800A0400

Any idea what is missing?
 
Static is not a recognised command in vbscript, well i dont recognise it :)
Try

Dim Depth

instead of Static Depth

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Mea culpa. Forgot that VBScript does not support static. You'll need to make it a global variable. Remove the line

Static Depth

from the function

and modify

Dim objexcel, r, lnameArray, lname, nameLength

to

Dim objexcel, r, lnameArray, lname, nameLength, Depth

In addition, just for fun add

Depth=0

after the line

ShowFolderDetails oFolder, r
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top