Creating a Dictionary
上一篇 /
下一篇 2010-03-29 19:58:37
/ 个人分类:VBScript
Chapter 5 Quick Reference
To |
Do This |
Use a string to populate an array |
Use the Split function to turn the string into an array |
Resize a dynamic array |
Use the ReDim command |
Resize a dynamic array and keep the existing data in it |
Use the ReDim command with the Preserve keyword |
Change the way string values are compared in a Dictionary object |
Change the Compare Mode property of the dictionary object |
Create a Dictionary object |
Use the createObject command and specify the scripting.dictionary program ID |
Determine how many items are in the dictionary |
Use the Count property |
Determine if an item exists in the dictionary prior to adding it |
Use the Exists method |
Obtain a collection of keys from the dictionary |
Use the Keys method |
YourNameDictionary.vbs
Option Explicit
Dim objDictionary 'the dictionary object
Dim objFSO 'the FileSystemObject object
Dim objFolder 'created by GetFolder method
Dim colFiles 'collection of files from Files method
Dim objFile 'individual file
Dim aryKeys 'array of keys
Dim strKey 'individual key from array of keys
Dim strFolder 'the folder to obtain listing of files
strFolder = "c:\windows"
Set bjDictionary = CreateObject("Scripting.Dictionary") 'connect dictionary
Set bjFSO = CreateObject("Scripting.FileSystemObject") ' connect filesystemobject
Set bjFolder = objFSO.GetFolder(strFolder) 'get path "c:\windows" all folders
Set colFiles = objFolder.Files
For Each objFile In colFiles 'using for each next to throgh all items with the files
objDictionary.Add objFile.Name, objFile.Size
Next
aryKeys = objDictionary.Keys
For Each strKey In aryKeys
WScript.Echo "The file: " & strKey & " is: " & _
objDictionary.Item(strKey) & " bytes"
Next
WScript.Echo "Directory listing of " & strFolder
WScript.Echo "***there are " & objDictionary.count & " files"
收藏
举报
TAG: