Solved

List files and folders in Access Database

Posted on 2013-12-21
1
443 Views
Last Modified: 2013-12-22
I'm trying to make a list of all my files and folders on my server into 2 access tables. One for all my files, and one for all my folders so I can use it as a search engine from a list box. Does anyone know how I could write the vba code to list the following info of my files and folders?

Directory
File Name
File Size
Last Modified
File Extension
File Path
File Created Date/TimeFile Owner?
File Accessed Last Date/Time
0
Comment
Question by:Lawrence Salvucci
1 Comment
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39734255
I have the important snippet below, and there is a full article on reading all the folders and files https://blogs.technet.com/b/heyscriptingguy/archive/2004/10/20/how-can-i-get-a-list-of-all-the-files-in-a-folder-and-its-subfolders.aspx

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Scripts"

Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.Path
Set colFiles = objFolder.Files
For Each objFile in colFiles
    Wscript.Echo objFile.Name
Next
Wscript.Echo

ShowSubfolders objFSO.GetFolder(objStartFolder)

Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        Wscript.Echo Subfolder.Path
        Set objFolder = objFSO.GetFolder(Subfolder.Path)
        Set colFiles = objFolder.Files
        For Each objFile in colFiles
            Wscript.Echo objFile.Name
        Next
        Wscript.Echo
        ShowSubFolders Subfolder
    Next
End Sub

Open in new window


What you would want to do is create your insert code in the for next statement to echo each individual file
For Each objFile in colFiles
    '** Wscript.Echo objFile.Name
     ' Place your insert script here
Next

Open in new window


From the list of properties http://msdn.microsoft.com/en-us/library/ea5ht6ax(v=vs.84).aspx you can choose what information you want to enter to your db.  The size property for instance http://msdn.microsoft.com/en-us/library/2d66skaf(v=vs.84).aspx is object.size  In the example above, you would use objFile.size.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now