Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Could someone please help me to understand

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,38211
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Could someone please help me to understand
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Could someone please help me to understand - 9/29/2006 1:27:33 AM   
  tkdvipers

 

Posts: 7
Score: 0
Joined: 9/29/2006
Status: offline
Hi

I am really new to this and I believe this is going to make a lot of you sigh. However I made a small script to list subfolders and files within a folder.

The script works however I don't understand why some of it does. Here is the script:

Option Explicit
 
Dim objFso, strUserInput, objFolder, foldl, subf, file
 
Set objFso = CreateObject("Scripting.FileSystemObject")
 
strUserInput = InputBox("Please enter the path of the folder you wish to find " & _
     "for example c:\windows\system32")

 
If objFso.FolderExists(strUserInput) Then

Set foldl = objFso.GetFolder(strUserInput)

For Each subf In foldl.SubFolders      < How does the script know what subf is?, I have declared it as a variable but thats all it is an empty variable

WScript.Echo subf.Name 

Next

For Each file In foldl.Files    < I have the same question here, why does it recognise file as a file object, when all I have done is declared it as a variable

WScript.Echo file.Name

Next

Else

WScript.Echo "No"

End If
 
I have put my questions by the parts of the script I don't understand. I don't understand why the script recognises that subf as a subfolder or file as a file. I have only declared them as variables and not given them values.

If someone could explain I would be most gratefull
 
 
Post #: 1
 
 RE: Could someone please help me to understand - 9/29/2006 1:33:40 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
You are working with Collections, and appointing members of the collection to subf and file, VBScript will then store each member of the collection in that variable.

For more info:
http://www.devguru.com/technologies/vbscript/14097.asp

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to tkdvipers)
 
 
Post #: 2
 
 RE: Could someone please help me to understand - 9/29/2006 1:34:59 AM   
  mikeock


Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
For Each subf In foldl.SubFolders


in the above line the subf acts like the iterator.
Instaed of doing a for i = 0 to foldl.subfolder.count
you are using the subf
so to access items it is doing a subf  rather than foldl.SubFolder.Item(i)

or something along those lines.

This code is not tested just shown as an example of why it works.

I really hope this makes sense!




Edit:
Apparently I am not the quickest poster.

< Message edited by mikeock -- 9/29/2006 1:35:59 AM >


_____________________________

My sig sucks!

(in reply to tkdvipers)
 
 
Post #: 3
 
 RE: Could someone please help me to understand - 9/29/2006 1:38:12 AM   
  tkdvipers

 

Posts: 7
Score: 0
Joined: 9/29/2006
Status: offline
Thanks very much both of you. That was really fast and it helped me loads. I want to understand why it works or doesn't for that matter.
I am much obliged to you

(in reply to mikeock)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Could someone please help me to understand Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts