Copying folder contents into a Dictionary (1 Viewer)

kirkm

Registered User.
Local time
Today, 13:35
Joined
Oct 30, 2008
Messages
1,257
I'd like to learn a bit about Dictionarys and want to copy the files in a folder into one. Can I do this directly, or do I need to copy files to an array first, then Array-Dictionary?

Thanks.
 

stopher

AWF VIP
Local time
Today, 02:35
Joined
Feb 1, 2006
Messages
2,395
Do you copy the file names? Or the links to the files? Or the contents of the files?

You would not normally use an array. You normally loop through you source data and add each element one by one directly to the dictionary.

Also note there is a Collection class which might be an alternative to Dictionary depending on what you are doing.

Please explain more about your requirements.
 

kirkm

Registered User.
Local time
Today, 13:35
Joined
Oct 30, 2008
Messages
1,257
It's the filenames. I have the following code

Code:
    'Load the files from Hard Drive
    MyFiles = BubbleSort2(gFindFiles(bbpath, "*" & bbType & ";*.nfo", UseAlbumSubfolders))
    
    'load the filenames into a dictionary
    Dim ofiles As Scripting.Dictionary
    Set ofiles = New Scripting.Dictionary
    ofiles.CompareMode = TextCompare 'Upper/lower case the same
    'iterate through the dictionary using string.Contains() function   ??  Doesn't seem to exist
    Dim i As Integer

    For i = 1 To UBound(MyFiles)
        ofiles.Add StripPath(MyFiles(i)), MyFiles(i)
    Next
    
    Stop
gfindFiles is a old routine I find still works ok to get the filenames to an array.
I'm playing with the Key and Item values to see what works best.

Maybe a Collection would be better, I'll have to do some Googling...

Thanks for reply :)
 

stopher

AWF VIP
Local time
Today, 02:35
Joined
Feb 1, 2006
Messages
2,395
It depends a lot on what you want to do with the data once it is in a data structure.
- do you reference by the key
- do you need to reference the key for a given entry
- do you need to sort
- do you need to check existence

For a dictionary I think the check for exists is EXISTS not Contains.

Note there are other structures you can use e.g. SortedList.

All depends what you want to do.
 

kirkm

Registered User.
Local time
Today, 13:35
Joined
Oct 30, 2008
Messages
1,257
Thanks for the info. Jdraws link was useful (didn't say much about searching though). I have a few things to try.. Stopher I eventually need all that but for now seeking the best way to get the filenames into the dictionary and being able to include or exclude subdirectories. Assuming how I'm doing it now can be bettered.
I can't get Exists to work for Items, only Keys.
 

Users who are viewing this thread

Top Bottom