Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Problem with recursion and objfolder.size
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
 
Pegasus [MVP]  
View profile  
 More options Nov 5 2009, 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...

> 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


    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.

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