e.g part00011222333.jpg, part00011222333.SVG, part00011222333.DWG, part00011222333.PDF
Is it safe to say that all of your file names will follow this pattern? It appears to be the same part number with different file extensions.
You'll notice in my example there is a field txtBaseName which is populated by an fso method GetBaseName(). GetBaseName() gets the file name without the extension.
You could use that to filter your records using a "Select Distinct txtBaseName . . " query.
FSO also has a GetExtensionName() method which can easily be used to filter out file types
Here's some code changes to the above example which filters out unwanted file types and duplicates.
Code:
Sub RecFso(FolPath As String)
Dim fso As New FileSystemObject
Dim fol As Folder
Dim fil As File
Dim sfol As Folder
Set fol = fso.GetFolder(FolPath)
For Each fil In fol.Files
Select Case fso.GetExtensionName(fil.Path)
Case "jpg", "png", "pdf", "svg", "dwg" 'Include the file types to include on this line
InsertToTable fil.Path, fil.Name, fso.GetExtensionName(fil.Path), fil.DateCreated, fil.DateLastModified, fso.GetBaseName(fil.Path)
Case Else
End Select
For Each sfol In fol.SubFolders
RecFso sfol.Path
Next
Next
End Sub
Sub InsertToTable(FPath As String, Fname As String, FExt As String, dteC As Date, dteM As Date, BN As String)
If DCount("*", "tblFiles", "FPath = """ & FPath & """") > 0 Then Exit Sub 'this will skip any file path already in table
Const Sql_Insert As String = _
"Insert into tblFiles" & _
"(FPath,FName,FExt,dteCreated,dteModified,txtBaseName)" & _
" Values(p0,p1,p2,p3,p4,p5)"
With CurrentDb.CreateQueryDef("", Sql_Insert)
.Parameters(0) = FPath
.Parameters(1) = Fname
.Parameters(2) = FExt
.Parameters(3) = dteC
.Parameters(4) = dteM
.Parameters(5) = BN
.Execute dbFailOnError
.Close
End With
End Sub