Go Back   Access World Forums > Microsoft Access Discussion > General

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-23-2016, 06:45 PM   #1
kirkm
Newly Registered User
 
Join Date: Oct 2008
Posts: 760
Thanks: 28
Thanked 24 Times in 24 Posts
kirkm is on a distinguished road
Copying folder contents into a Dictionary

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.

kirkm is offline   Reply With Quote
Old 08-23-2016, 11:09 PM   #2
stopher
AWF VIP
 
stopher's Avatar
 
Join Date: Feb 2006
Location: Southampton, UK
Posts: 2,396
Thanks: 20
Thanked 311 Times in 292 Posts
stopher is a jewel in the rough stopher is a jewel in the rough stopher is a jewel in the rough stopher is a jewel in the rough
Re: Copying folder contents into a Dictionary

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.
stopher is offline   Reply With Quote
Old 08-24-2016, 12:10 AM   #3
kirkm
Newly Registered User
 
Join Date: Oct 2008
Posts: 760
Thanks: 28
Thanked 24 Times in 24 Posts
kirkm is on a distinguished road
Re: Copying folder contents into a Dictionary

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

kirkm is offline   Reply With Quote
Old 08-24-2016, 03:44 AM   #4
stopher
AWF VIP
 
stopher's Avatar
 
Join Date: Feb 2006
Location: Southampton, UK
Posts: 2,396
Thanks: 20
Thanked 311 Times in 292 Posts
stopher is a jewel in the rough stopher is a jewel in the rough stopher is a jewel in the rough stopher is a jewel in the rough
Re: Copying folder contents into a Dictionary

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.
stopher is offline   Reply With Quote
Old 08-24-2016, 04:06 AM   #5
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,379
Thanks: 101
Thanked 2,058 Times in 2,002 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Copying folder contents into a Dictionary

kirkm,

This info re Dictionaries and Arrays may be useful.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
The Following User Says Thank You to jdraw For This Useful Post:
stopher (08-24-2016)
Old 08-24-2016, 02:36 PM   #6
kirkm
Newly Registered User
 
Join Date: Oct 2008
Posts: 760
Thanks: 28
Thanked 24 Times in 24 Posts
kirkm is on a distinguished road
Re: Copying folder contents into a Dictionary

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.
kirkm is offline   Reply With Quote
Old 08-24-2016, 03:09 PM   #7
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,379
Thanks: 101
Thanked 2,058 Times in 2,002 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Copying folder contents into a Dictionary

Here is another link re Dictionaries in vba MSAccess.


__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
jdraw is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question Can The Contents Of A Folder Be Displayed? Groundrush General 2 12-07-2010 12:14 AM
Emailing contents of folder jfgambit Modules & VBA 4 08-22-2008 11:20 PM
copying contents of one field to another [duplicating] pam0566 Tables 1 07-31-2008 08:20 PM
Viewing contents of a single folder Anthony George Modules & VBA 7 12-17-2006 04:40 AM
Copying Table Contents kappa Tables 2 05-18-2005 11:43 PM




All times are GMT -8. The time now is 05:27 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World