Can someone tell me this sample script out of the Microsoft Press book
by Ed Wilson won't run properly?
When I run it is displays every file in the folder, the same number of
times that there are files in the folder....
IE...if there are nine files in the folder it shows all nine files nine
times with a different file size for each one. Any help would be
appreciated.
Thanks:

'===================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies
PrimalSCRIPT(TM)
'
' NAME: <filename>
'
' AUTHOR: ed wilson , mred
' DATE : 9/21/2003
'
' COMMENT: <comment>
'
'===================================================================
Option Explicit
Dim objDictionary
Dim objFSO
Dim objFolder
Dim colFiles
Dim objFile
Dim colItems
Dim colKeys
Dim strKey
Dim strItem

Set objDictionary = CreateObject("scripting.dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\scriptingBook")
Set colFiles = objFolder.Files

For Each objFile In colFiles
objDictionary.Add objFile.Name, objFile.Size
Next


colItems = objDictionary.Items
colKeys = objDictionary.Keys

For Each strKey In colKeys
For Each strItem In colItems
WScript.Echo "filename: " & strKey & " size: " & strItem
Next
Next

WScript.Echo "***there are " & objDictionary.Count & " files"

Re: Sample Dictionary Script(Newbie) by McKirahan

McKirahan
Fri Nov 04 11:29:27 CST 2005

<matthaught@gmail.com> wrote in message
news:1131120904.545351.18140@o13g2000cwo.googlegroups.com...
> Can someone tell me this sample script out of the Microsoft Press book
> by Ed Wilson won't run properly?
> When I run it is displays every file in the folder, the same number of
> times that there are files in the folder....
> IE...if there are nine files in the folder it shows all nine files nine
> times with a different file size for each one. Any help would be
> appreciated.
> Thanks:
>
> '===================================================================
> '
> ' VBScript Source File -- Created with SAPIEN Technologies
> PrimalSCRIPT(TM)
> '
> ' NAME: <filename>
> '
> ' AUTHOR: ed wilson , mred
> ' DATE : 9/21/2003
> '
> ' COMMENT: <comment>
> '
> '===================================================================

[snip]

Is this what you want?

Option Explicit
Dim objDictionary
Dim objFSO
Dim objFolder
Dim colFiles
Dim objFile
Dim colKeys
Dim strKey
Dim strFiles

Set objDictionary = CreateObject("scripting.dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Temp")
Set colFiles = objFolder.Files

For Each objFile In colFiles
objDictionary.Add objFile.Name, objFile.Size
Next

colKeys = objDictionary.Keys

For Each strKey In colKeys
strFiles = strFiles & vbCrLf & "filename: " & strKey & " size: " &
objDictionary.Item(strKey)
Next

WScript.Echo "***there are " & objDictionary.Count & " files :" & strFiles



Re: Sample Dictionary Script(Newbie) by matthaught

matthaught
Fri Nov 04 11:56:05 CST 2005

Yes. Now I just need to figure out what sets yours apart from the
sample.
thanks.


Re: Sample Dictionary Script(Newbie) by McKirahan

McKirahan
Fri Nov 04 12:05:19 CST 2005

<matthaught@gmail.com> wrote in message
news:1131126965.527178.257750@g14g2000cwa.googlegroups.com...
> Yes. Now I just need to figure out what sets yours apart from the
> sample.
> thanks.
>

It looped through the items within a loop through each key.



Re: Sample Dictionary Script(Newbie) by ESP

ESP
Fri Nov 04 15:15:04 CST 2005

Also, something a lot of techs just getting into VBS don't realize is that
Win O/S objects are different on different versions of Windows. So, not every
script that is written/found works on all versions of Windows. Of course,
responsible scriptors will make their code as compatible as possible, but it
does happen.

Here's another reference point in your search:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0218.mspx

ESP



"McKirahan" wrote:

> <matthaught@gmail.com> wrote in message
> news:1131126965.527178.257750@g14g2000cwa.googlegroups.com...
> > Yes. Now I just need to figure out what sets yours apart from the
> > sample.
> > thanks.
> >
>
> It looped through the items within a loop through each key.
>
>
>