Web Images News Groups Scholar Blogs Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Problem with recursion and objfolder.size
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeremy  
View profile  
 More options Nov 5, 5:41 am
Newsgroups: microsoft.public.scripting.vbscript
From: Jeremy <Jer...@discussions.microsoft.com>
Date: Wed, 4 Nov 2009 21:41:02 -0800
Local: Thurs, Nov 5 2009 5:41 am
Subject: 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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pegasus [MVP]  
View profile  
 More options Nov 5, 6:57 am
Newsgroups: microsoft.public.scripting.vbscript
From: "Pegasus [MVP]" <n...@microsoft.com>
Date: Thu, 5 Nov 2009 07:57:15 +0100
Local: Thurs, Nov 5 2009 6:57 am
Subject: Re: Problem with recursion and objfolder.size

"Jeremy" <Jer...@discussions.microsoft.com> wrote in message

news:A199E020-3C43-4FF0-8023-F170B091547D@microsoft.com...

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy  
View profile  
 More options Nov 5, 2:46 pm
Newsgroups: microsoft.public.scripting.vbscript
From: Jeremy <Jer...@discussions.microsoft.com>
Date: Thu, 5 Nov 2009 06:46:03 -0800
Local: Thurs, Nov 5 2009 2:46 pm
Subject: 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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy  
View profile  
 More options Nov 5, 4:01 pm
Newsgroups: microsoft.public.scripting.vbscript
From: Jeremy <Jer...@discussions.microsoft.com>
Date: Thu, 5 Nov 2009 08:01:02 -0800
Local: Thurs, Nov 5 2009 4:01 pm
Subject: 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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Lavedas  
View profile  
 More options Nov 5, 4:36 pm
Newsgroups: microsoft.public.scripting.vbscript
From: Tom Lavedas <tglba...@cox.net>
Date: Thu, 5 Nov 2009 08:36:24 -0800 (PST)
Local: Thurs, Nov 5 2009 4:36 pm
Subject: Re: Problem with recursion and objfolder.size
On Nov 5, 11:01 am, Jeremy <Jer...@discussions.microsoft.com> wrote:

> 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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pegasus [MVP]  
View profile  
 More options Nov 5, 5:42 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "Pegasus [MVP]" <n...@microsoft.com>
Date: Thu, 5 Nov 2009 18:42:09 +0100
Local: Thurs, Nov 5 2009 5:42 pm
Subject: Re: Problem with recursion and objfolder.size

"Jeremy" <Jer...@discussions.microsoft.com> wrote in message

news:2591F773-4282-4B91-BFAA-2D75A7982147@microsoft.com...

> 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?

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy  
View profile  
 More options Nov 11, 3:44 pm
Newsgroups: microsoft.public.scripting.vbscript
From: Jeremy <Jer...@discussions.microsoft.com>
Date: Wed, 11 Nov 2009 07:44:02 -0800
Local: Wed, Nov 11 2009 3:44 pm
Subject: 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!!!"


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google