I have a folder that has data files with dates, and I to get that data into an excel spreadsheet so I can create an ACCESS table. I have found a way to get the file names but cant get into excel but not the dates.
Thanks
Thanks
I have a folder that has various audio files stored in m4a format, (Created bt the Sound Recorder) and I want to create a list of the filenames and dates created that I can convert to .csv file and load into ACCESS. My problem is I do not understand the file system the the files are stored in. The recorder has a popup menu where you can add fields to be viewed. I can get a list of the names, but I also need the date that are associated with each file.Not sure what you are doing, but if looping the files in a folder using filesystemobject you can use the File Object which has a dateCreated, dateLastAccessed, and dateLastModified property.
Solved - Access VBA - Loop through files in Folders, Subfolders, Sub-Sub Folders....
Hi, Before I write my own nested nested nested loop, surely someone has something out there already.... I need to list all the files in a single 'base' folder, which includes subfolders of the base folder. and subfolders of the subfolder's subfolders. The nesting of the subfolders is assumed...www.access-programmers.co.uk
Why the csv? You can load directly into the access table.I want to create a list of the filenames and dates created that I can convert to .csv file and load into ACCESS.
So you're OK with running hundreds, perhaps thousands of separate queries (one for each file) rather than opening a recordset and using .AddNew??? Surely, there has to be some overhead involved with forcing Access to create hundreds/thousands of query execution plans and then compile them so they can be executed. Maybe Access is smart enough to create a querydef and reuse it. But, someone with intimate knowledge of how the query process works internally would have to jump in to confirm. Even still, running hundreds/thousands of queries, even if there is no need to keep creating new execution plans and compiling them, just running the separate queries can't be right.Using a parameter query is also a very good style.
It was meant as a quick and dirty example how it could be done.@moke123 Thanks for posting an example. Any particular reason you chose to run an append query for each file rather than just opening a recordset and using .AddNew?
Moke, it works like a champ. Always like your answers. Now the challenge for me is to figure out why it works. I don't understand the code at all.Why the csv? You can load directly into the access table.
The vast majority of my queries take parameters. I recommend them almost daily. The difference from what you see in this example is that I use saved querydefs. I do not build SQL using VBA when the SQL is not dynamic. I find it to be a unique point of view. Because the QBE's SQL string editor is pretty crummy, many people turn up their nose and refuse to use it thinking that building SQL strings in code is somehow "superior".Overall, I am also pleased that a parameter query was used at all instead of assembling the SQL statement using VBA. Readers see that far too seldom. It should be mastered and therefore written off.
Public Sub sAddFilesToListBox(TopFold As String, Lbx As ListBox)
Set fso = New FileSystemObject
Set fCol = New Collection
fCol.Add TopFold 'add the top folder path to the collection
sGetFolderCollection TopFold 'call recursive proc to add subfolder paths to collection
Lbx.rowsource = ""
Dim i As Long
Dim Fldr As Folder, fl As File
For i = 1 To fCol.Count 'loop through the collection of folder paths
Set Fldr = fso.GetFolder(fCol(i))
For Each fl In Fldr.Files 'loop through folder adding file info to table
Lbx.AddItem fl.Name & ";" & fl.Path & ";" & fl.DateCreated & ";" & fl.DateLastModified
Next
Next i
End Sub
Sub sGetFolderCollection(TopFold As String)
Dim oTopFolder As Folder
Dim fol As Folder
Dim sfol As Folder
Set oTopFolder = fso.GetFolder(TopFold)
For Each fol In oTopFolder.SubFolders
fCol.Add fol.Path
For Each sfol In fol.SubFolders
Call sGetFolderCollection(sfol.Path)
Next
Next fol
End Sub
sAddFilesToListBox strPath, Me.lstFiles
Moke, I have been using the example you sent, but the code is a bit above my experience level with VBA. But, your example clarified my thinking about what I was trying to do. I use the Voice Recorder to record various calls, conversations,etc. Voice Recorder stores those recordings in Documents\Sound Recordings. I know the path to the files, so I don't need to enter it each time. I need some help with code that would reside behind a button that would get the latest recordings and their properties; those files that are later than the last date in a table in an ACCESS database. There is other information that needs to be added to the table, which can only be done by hand, but if I can get the recording name and the start and modified time I can reduce what has to be entered by hand. The flow would look like this:I'm not sure what your end goal is but one thing to be careful of is keeping data current if folders and files get added or deleted.
I usually avoid using a table for this type stuff. In my instance, I have a folder for each client and all docs and files, etc. for that client go in that folder. When I open a clients profile form, I run a procedure to list just their files in a list box. I can double click it to open the listed file. The data will always be current if files were added or deleted.
If you want to try the listbox route the relevant code is
Code:Public Sub sAddFilesToListBox(TopFold As String, Lbx As ListBox) Set fso = New FileSystemObject Set fCol = New Collection fCol.Add TopFold 'add the top folder path to the collection sGetFolderCollection TopFold 'call recursive proc to add subfolder paths to collection Lbx.rowsource = "" Dim i As Long Dim Fldr As Folder, fl As File For i = 1 To fCol.Count 'loop through the collection of folder paths Set Fldr = fso.GetFolder(fCol(i)) For Each fl In Fldr.Files 'loop through folder adding file info to table Lbx.AddItem fl.Name & ";" & fl.Path & ";" & fl.DateCreated & ";" & fl.DateLastModified Next Next i End Sub
It also uses this procedure which is in the example I posted
Code:Sub sGetFolderCollection(TopFold As String) Dim oTopFolder As Folder Dim fol As Folder Dim sfol As Folder Set oTopFolder = fso.GetFolder(TopFold) For Each fol In oTopFolder.SubFolders fCol.Add fol.Path For Each sfol In fol.SubFolders Call sGetFolderCollection(sfol.Path) Next Next fol End Sub
You would call it with
strPath is the path to your top folder, and replace lstFiles with the name of your value list listbox.Code:sAddFilesToListBox strPath, Me.lstFiles
Date Created, Date modified, etc. Right click on a file to see it's properties.What properties? "the latest recordings and their properties;"
If listing to a table, do you want to get only the new files, or just the latest? How many files to you anticipate having?a button that would get the latest recordings and their properties; those files that are later than the last date in a table in an ACCESS
I gave you 2 options, Save to table and list in a list box. Which one are you using?
If listing to a table, do you want to get only the new files, or just the latest? How many files to you anticipate having?
I gave you 2 options, Save to table and list in a list box. Which one are you using?
If listing to a table, do you want to get only the new files, or just the latest? How many files to you anticipate h
There is no real volume, maybe 5 or 6 recordings max in a day, but mostly less. I am currently using your example as a utility external to ACCESS. I run your example , then export Table1 from your example to my ACCESS app,(after deleting the previous one and saving the max datetime). I then can create what I need with queries. I create a query that then gets all the files that are newer on the new Table1 than the max date from the previous table1. I want to automate that process, but I am having a difficult time understanding your code. I've been running it over and over with a lot debug.prints to try and understand the part that I need. I will continue to work on it. But, some of the terms in your code I can't find anywhere on the web..I gave you 2 options, Save to table and list in a list box. Which one are you using?
If listing to a table, do you want to get only the new files, or just the latest? How many files to you anticipate having?
Post what you don't understand and we'll explain.I will continue to work on it. But, some of the terms in your code I can't find anywhere on the web..