Access 2007-2016
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
 
Home   News   Tips   Glossary   Templates   Forums   Help   Logon   Order   Contact Us  
 
Tips & Tricks

New Tips Added Weekly!
Click here to get on our Mailing List

   
 
MS Access

List Files in a Folder

How to get a List of all files in a Folder

You have a folder full of images that you want to add to a database.

Create a Table called tblPictures with the following schema:

FieldNameDataType
PictureIDAutonumber
PicturePathText
PictureNameText
PictureSizeInteger

Now you can create a Module in Access and add the following code.

Just call the Function passing in your folder.

ListFiles("D:\Folder\")

	Option Compare Database
	' Add Ref to Microsoft Scripting Runtime
	Sub ListFiles(mySourcePath)
		 
		Dim Counter As Integer
		 
		Set myObject = New Scripting.FileSystemObject
		Set mySource = myObject.GetFolder(mySourcePath)
		 
		On Error Resume Next
		 
		Dim db As Database
		Dim rs As Recordset
		Dim mysql As String
		 
		Set db = CurrentDb
		mysql = "tblPictures"
		Set rs = db.OpenRecordset(mysql, dbOpenDynaset)
		 
		For Each myFile In mySource.Files
			rs.AddNew
			rs![PicturePath] = myFile.Path
			rs![PictureName] = myFile.Name
			rs![PictureSize] = myFile.Size
			rs.Update
			 
			Counter = Counter + 1
		Next
		 
		' Clean up
		rs.Close
		db.Close
		Set rs = Nothing
		Set db = Nothing
		
		Set myObject = Nothing
		Set mySource = Nothing
		
		MsgBox "Listed " & Counter & " Files."
		 
	End Sub
	
tblPictures
PictureIDPicturePathPictureNamePictureSize
55D:\...\Blank.pngBlank.png1794
56D:\...\Datasheet.pngDatasheet.png1862

Download Source

Source

 

Alex Hedley (Avatar) By: Alex Hedley


Click here to sign up for more FREE tips

 

You may want to read these articles from the 599CD News:

 

Learn
 
Accessindex
Excelindex
Wordindex
Windowsindex
PowerPointindex
Photoshopindex
Visual Basicindex
ASPindex
Seminars
More...
Customers
 
Account Login
Online Theater
Downloads
Lost Password
Free Upgrades
Insider Circle
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Articles
Search Our Site
Waiting List
Production Schedule
Collapse Menus
Help
 
Live Chat
Customer Support
WalkThru Tutorials
Troubleshooting
FAQs
TechHelp
Consulting Services
About Us
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
MYOLP Memberships
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Gift CDs
Contact
 
Live Chat
General Info
Support Policy
Contact Form
Email Us
Mailing Address
Phone Number
Fax Number
Course Survey
Facebook    Twitter

Google Plus    LinkedIn

Blog RSS Feed    YouTube Channel
Richard Rost Microsoft MVP