PDA

View Full Version : Solved: Return all file names in a folder



jtrowbridge
09-03-2008, 12:01 PM
Anyone know how to import all of the file names in a folder into an array?

Here's what I'd like to be able to do:

for the following folder 'c:\test' the contents are:
file1.txt
file2.txt
file3.txt


I'd like to be able to check the file contents of c:\test\ and somehow have the three filenames written into an array (as strings). First the script needs to count the number of files in the folder and then loop through each file name so that it can write each name into the array. I'll then do some string manipulation to check that certian files are present in the folder before starting a secondary process.


I've been reading up on the FileSystemObject but I'm afraid I haven't figured out how to use that object to figure this out.

Any help would be appreciated. I feel like this shouldnt be very hard to do, i just dont know what functions to use. :think:

Thanks!

CreganTur
09-04-2008, 05:15 AM
This kb article from mdmackillop (http://vbaexpress.com/kb/getarticle.php?kb_id=245&PHPSESSID=7c996128442f2dab6d32318705c1d853) shows how you can loop through all files in folders and subfolders. You could adapt this to your needs.

jtrowbridge
09-04-2008, 07:42 AM
That's a nice little chunk of code, that'll do the trick nicely. I'm liking it alot!

Thanks for the help!