Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

List files and folders in Access Database

Posted on 2013-12-21
1
445 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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