Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Problem with recursion and objfolder.size

Reply
 
Old 2 Weeks Ago   #1 (permalink)
Jeremy


 
 

Problem with recursion and objfolder.size

1l The purpose of the following script is to return attributes of subfolders
into an Excel spread sheet. The way it is now, it only gives the attirbutes
for the root folder. I know I need to add a for...next. I just don't know
what to put after the for.

2. I get a permissions error with the objfolderf.size line, but not with
other lines.

Any suggestions please?

--------------------------------
'Script to get info on sub folders

'Section 1 - Excel Stuff
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add

intRow = 2

objExcel.Cells(1, 1).Value = "Date Created"
objExcel.Cells(1, 2).Value = "Date Last Accessed"
objExcel.Cells(1, 3).Value = "Date Last Modified"
objExcel.Cells(1, 4).Value = "Name"
objExcel.Cells(1, 5).Value = "Path"
objExcel.Cells(1, 6).Value = "Size"
objExcel.Cells(1, 7).Value = "Type"


'Section 2 - Find folder Attributes

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("f:\jeremy-data")

'For each objFolder in objFSO.GetFolder

objExcel.Cells(intRow, 1).Value = objFolder.DateCreated
objExcel.Cells(intRow, 2).Value = objFolder.DateLastAccessed
objExcel.Cells(intRow, 3).Value = objFolder.DateLastModified
objExcel.Cells(intRow, 4).Value = objFolder.Name
objExcel.Cells(intRow, 5).Value = objFolder.Path
objExcel.Cells(intRow, 6).Value = objFolder.Size
objExcel.Cells(intRow, 7).Value = objFolder.Type

'Next

My System SpecsSystem Spec
Old 2 Weeks Ago   #2 (permalink)
Pegasus [MVP]


 
 

Re: Problem with recursion and objfolder.size


"Jeremy" <Jeremy@newsgroup> wrote in message
news:A199E020-3C43-4FF0-8023-F170B091547D@newsgroup
Quote:

> 1l The purpose of the following script is to return attributes of
> subfolders
> into an Excel spread sheet. The way it is now, it only gives the
> attirbutes
> for the root folder. I know I need to add a for...next. I just don't
> know
> what to put after the for.
>
> 2. I get a permissions error with the objfolderf.size line, but not with
> other lines.
>
> Any suggestions please?
>
> --------------------------------
> 'Script to get info on sub folders
>
> 'Section 1 - Excel Stuff
> Set objExcel = CreateObject("Excel.Application")
> objExcel.Visible = True
> objExcel.Workbooks.Add
>
> intRow = 2
>
> objExcel.Cells(1, 1).Value = "Date Created"
> objExcel.Cells(1, 2).Value = "Date Last Accessed"
> objExcel.Cells(1, 3).Value = "Date Last Modified"
> objExcel.Cells(1, 4).Value = "Name"
> objExcel.Cells(1, 5).Value = "Path"
> objExcel.Cells(1, 6).Value = "Size"
> objExcel.Cells(1, 7).Value = "Type"
>
>
> 'Section 2 - Find folder Attributes
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder("f:\jeremy-data")
>
> 'For each objFolder in objFSO.GetFolder
>
> objExcel.Cells(intRow, 1).Value = objFolder.DateCreated
> objExcel.Cells(intRow, 2).Value = objFolder.DateLastAccessed
> objExcel.Cells(intRow, 3).Value = objFolder.DateLastModified
> objExcel.Cells(intRow, 4).Value = objFolder.Name
> objExcel.Cells(intRow, 5).Value = objFolder.Path
> objExcel.Cells(intRow, 6).Value = objFolder.Size
> objExcel.Cells(intRow, 7).Value = objFolder.Type
>
> 'Next
It helps to see things more clearly if you add a little more structure to
your code. The script below should emphasizes the recursive component of
your code. Its core is the subroutine "ProcessFolder". You first call it
with the root folder name "f:\jeremy-data", then from within itself with the
name of each subfolder that exists.

Set objFSO = CreateObject("Scripting.FileSystemObject")
sFolder = "f:\jeremy-data"
ProcessFolder(sFolder)

Sub ProcessFolder(sFolderName)
Set objFolder = objFSO.GetFolder(sFolderName)
For Each objSubFolder In objFolder.SubFolders
DoExcelStuff objSubFolder
ProcessFolder(objSubFolder.Path)
Next
End Sub

Sub DoExcelStuff (objFolder)
WScript.Echo objFolder.DateCreated
WScript.Echo objFolder.DateLastAccessed
WScript.Echo objFolder.DateLastModified
WScript.Echo objFolder.Name
WScript.Echo objFolder.Path
WScript.Echo objFolder.Size
WScript.Echo objFolder.Type
End Sub


My System SpecsSystem Spec
Old 2 Weeks Ago   #3 (permalink)
Jeremy


 
 

RE: Problem with recursion and objfolder.size

Solved the recursive part, see below. Now just need help with the
permissions issue when asking for the folder size attribute.

'Script to get info on sub folders

'Section 1 - Excel Stuff
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add

intRow = 2

objExcel.Cells(1, 1).Value = "Date Created"
objExcel.Cells(1, 2).Value = "Date Last Accessed"
objExcel.Cells(1, 3).Value = "Date Last Modified"
objExcel.Cells(1, 4).Value = "Name"
objExcel.Cells(1, 5).Value = "Path"
objExcel.Cells(1, 6).Value = "Size"
objExcel.Cells(1, 7).Value = "Type"


'Section 2 - Find folder Attributes

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("f:\jeremy-data")

for each objFolder in objFolder.SubFolders

objExcel.Cells(intRow, 1).Value = objFolder.DateCreated
objExcel.Cells(intRow, 2).Value = objFolder.DateLastAccessed
objExcel.Cells(intRow, 3).Value = objFolder.DateLastModified
objExcel.Cells(intRow, 4).Value = objFolder.Name
objExcel.Cells(intRow, 5).Value = objFolder.Path
'objExcel.Cells(intRow, 6).Value = objFolder.Size
objExcel.Cells(intRow, 7).Value = objFolder.Type
intRow = intRow + 1


Next

"Jeremy" wrote:
Quote:

> 1l The purpose of the following script is to return attributes of subfolders
> into an Excel spread sheet. The way it is now, it only gives the attirbutes
> for the root folder. I know I need to add a for...next. I just don't know
> what to put after the for.
>
> 2. I get a permissions error with the objfolderf.size line, but not with
> other lines.
>
> Any suggestions please?
>
> --------------------------------
> 'Script to get info on sub folders
>
> 'Section 1 - Excel Stuff
> Set objExcel = CreateObject("Excel.Application")
> objExcel.Visible = True
> objExcel.Workbooks.Add
>
> intRow = 2
>
> objExcel.Cells(1, 1).Value = "Date Created"
> objExcel.Cells(1, 2).Value = "Date Last Accessed"
> objExcel.Cells(1, 3).Value = "Date Last Modified"
> objExcel.Cells(1, 4).Value = "Name"
> objExcel.Cells(1, 5).Value = "Path"
> objExcel.Cells(1, 6).Value = "Size"
> objExcel.Cells(1, 7).Value = "Type"
>
>
> 'Section 2 - Find folder Attributes
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder("f:\jeremy-data")
>
> 'For each objFolder in objFSO.GetFolder
>
> objExcel.Cells(intRow, 1).Value = objFolder.DateCreated
> objExcel.Cells(intRow, 2).Value = objFolder.DateLastAccessed
> objExcel.Cells(intRow, 3).Value = objFolder.DateLastModified
> objExcel.Cells(intRow, 4).Value = objFolder.Name
> objExcel.Cells(intRow, 5).Value = objFolder.Path
> objExcel.Cells(intRow, 6).Value = objFolder.Size
> objExcel.Cells(intRow, 7).Value = objFolder.Type
>
> 'Next
My System SpecsSystem Spec
Old 2 Weeks Ago   #4 (permalink)
Jeremy


 
 

RE: Problem with recursion and objfolder.size

I'm wrong, what I have below only recurses one level. How do I get this to
apply to all sub folders? Thx, Jeremy

"Jeremy" wrote:
Quote:

> 1l The purpose of the following script is to return attributes of subfolders
> into an Excel spread sheet. The way it is now, it only gives the attirbutes
> for the root folder. I know I need to add a for...next. I just don't know
> what to put after the for.
>
> 2. I get a permissions error with the objfolderf.size line, but not with
> other lines.
>
> Any suggestions please?
>
> --------------------------------
> 'Script to get info on sub folders
>
> 'Section 1 - Excel Stuff
> Set objExcel = CreateObject("Excel.Application")
> objExcel.Visible = True
> objExcel.Workbooks.Add
>
> intRow = 2
>
> objExcel.Cells(1, 1).Value = "Date Created"
> objExcel.Cells(1, 2).Value = "Date Last Accessed"
> objExcel.Cells(1, 3).Value = "Date Last Modified"
> objExcel.Cells(1, 4).Value = "Name"
> objExcel.Cells(1, 5).Value = "Path"
> objExcel.Cells(1, 6).Value = "Size"
> objExcel.Cells(1, 7).Value = "Type"
>
>
> 'Section 2 - Find folder Attributes
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder("f:\jeremy-data")
>
> 'For each objFolder in objFSO.GetFolder
>
> objExcel.Cells(intRow, 1).Value = objFolder.DateCreated
> objExcel.Cells(intRow, 2).Value = objFolder.DateLastAccessed
> objExcel.Cells(intRow, 3).Value = objFolder.DateLastModified
> objExcel.Cells(intRow, 4).Value = objFolder.Name
> objExcel.Cells(intRow, 5).Value = objFolder.Path
> objExcel.Cells(intRow, 6).Value = objFolder.Size
> objExcel.Cells(intRow, 7).Value = objFolder.Type
>
> 'Next
My System SpecsSystem Spec
Old 2 Weeks Ago   #5 (permalink)
Tom Lavedas


 
 

Re: Problem with recursion and objfolder.size

On Nov 5, 11:01*am, Jeremy <Jer...@newsgroup> wrote:
Quote:

> I'm wrong, what I have below only recurses one level. *How do I get this to
> apply to all sub folders? *Thx, Jeremy
>
Here is an example I had handy ...

' A simple example of making a recursive list of files in a
' folder and all of its subfolders
' Derived from examples by Michael Harris, Torgier Bakken and
' others

Dim ofs ' a global reference to an instance of the FileSystemObject
Dim aFileSpecs

With CreateObject("WScript.Shell")
dpath = .SpecialFolders("MyDocuments")
End With
Set ofs = CreateObject("Scripting.FileSystemObject")

' One way to use the list is to break it up into an array
aFileSpecs = Split(getList(dPath, ofs), vbNewline)

wsh.echo "Found:", UBound(aFileSpecs), "file(s)"
wsh.echo Join(aFileSpecs, vbNewLine)

Function getList(sPath, ofs)
Dim s
s = ""
With ofs.GetFolder(sPath)
s = s & sPath & vbNewLine
if .SubFolders.Count > 0 Then
For each folder in .SubFolders
' Change this part to collect the information you want
s = s & getList(sPath & "\" & folder.Name, ofs)
Next
End if
End With
getList = s
End Function
_____________________
Tom Lavedas
My System SpecsSystem Spec
Old 2 Weeks Ago   #6 (permalink)
Pegasus [MVP]


 
 

Re: Problem with recursion and objfolder.size


"Jeremy" <Jeremy@newsgroup> wrote in message
news:2591F773-4282-4B91-BFAA-2D75A7982147@newsgroup
Quote:

> I'm wrong, what I have below only recurses one level. How do I get this
> to
> apply to all sub folders? Thx, Jeremy
>
Did you actually read my detailed response to your first post?


My System SpecsSystem Spec
Old 1 Week Ago   #7 (permalink)
Jeremy


 
 

RE: Problem with recursion and objfolder.size

Thank you both for your help. I'm reading through your suggestions, (which
I've only seen now, for some reason, I never see responses right away,
anyway....). I did find another script on another forum that helped me mash
out what I want to do. I've modified it to my needs and it seems to work
well. It saves everything to a text file we I can then open in Excel. So
just a few extra steps are required to convert the text data into Excel
format. But now that I think I have the concept down, I may try 'convert' it
to use Excel. There was one good point about exporting things to a log file.
It never occured to me that my users might use a comma in the name of their
word processing files! So I had to switch to using a semi colon for a
delimeter. Anyway, for anyone who is interested, here is my revised code.
And thanks again for the suggestions from both of you. Jeremy

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const ForAppending = 2

Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")

Wscript.echo "Script is about to start!"

LogFile = "l:\exportme7.txt"

Dim objLogFile:Set objLogFile = objFSO.CreateTextFile(logfile, 2, True)


objStartFolder = "L:\"


Set objFolder = objFSO.GetFolder(objStartFolder)

objLogFile.write "Name;" & "Created;" & "Last Modified;" & "Size;" & "Path;"
& "Type"

objLogFile.Writeline

objLogFile.Write objFolder.Name & ";;;"

'objLogFile.Write objFolder.datecreated & ";"

'objLogFile.Write objFolder.datelastmodified & ";"

'objLogFile.Write objFolder.size & ";"

objLogFile.Write objFolder.Path & ";"

objLogFile.Writeline

Set colFiles = objFolder.Files

For Each objFile in colFiles

objLogFile.Write objFile.Name & ";"

objLogFile.write objFile.datecreated & ";"

objLogFile.write objFile.datelastmodified & ";"

objLogFile.write objFile.size & ";"

objLogFile.Write objFile.path & ";"

objLogFile.Write objFile.Type

objLogFile.Writeline

Next


ShowSubfolders objFSO.GetFolder(objStartFolder)


Sub ShowSubFolders(Folder)

For Each Subfolder in Folder.SubFolders

objLogfile.Write subfolder.Name & ";"

objLogFile.write subfolder.datecreated & ";"

objLogFile.write subfolder.datelastmodified & ";"

objLogFile.write subfolder.size & ";"

objLogFile.Write Subfolder.Path & ";"

objLogFile.write subfolder.Type

objLogFile.Writeline

Set objFolder = objFSO.GetFolder(Subfolder.Path)

Set colFiles = objFolder.Files

For Each objFile in colFiles

objLogFile.Write objFile.Name & ";"

objLogFile.Write objFile.datecreated & ";"

objLogFile.Write objFile.datelastmodified & ";"

objLogFile.Write objFile.size & ";"

objLogFile.Write objFile.path & ";"

objLogFile.write objFile.type

objLogFile.Writeline

Next

ShowSubFolders Subfolder

Next

End Sub


objLogFile.Close


wscript.echo "Script Finished!!!"

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
recursion help request VB Script
Xml, Recursion and Base64 PowerShell
Xml and Recursion PowerShell
Xml, recursion and Ôase64 PowerShell
How do I limit subfolder recursion? VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46