Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Get Path & Filename list in a DB?

Status
Not open for further replies.

MrVB50au

Programmer
Mar 16, 2003
326
AU
I have an app that collects picture files, the path and filenames stored into a database field called 'FILES'.

I want to add a group of files from a filelistbox and have them stored into the database field 'FILES' but don't want to do the painstaking task in collecting them one by one the way I'm doing it now.

I'm sure that there's a simply way as to do this but just can't seem to think for the life of me.


Can anyone please help?

Would be really greatful,

Thanks in advance,

Andrew.

 
Hi,
You could use the Dir$ function in something like this

Function GetFiles(filespec As String, Optional Attributes As _
vbFileAttributes) As String()
Dim result() As String
Dim filename As String, count As Long
Const ALLOC_CHUNK = 50
ReDim result(0 To ALLOC_CHUNK) As String
filename = Dir$(filespec, Attributes)
Do While Len(filename)
count = count + 1
If count > UBound(result) Then
'Resize the result array if necessary
ReDim Preserve result(0 To count + ALLOC_CHUNK) As String
End If
result(count) = filename

'Get ready for the next iteration
filename = Dir$
Loop
'Trim the result array
ReDim Preserve result(0 To count) As String
GetFiles = result
End Function

Then in a procedure

Private Sub Command1_Click()
Dim files() As String, i As Long
files() = GetFiles("C:\Windows\", vbNormal + vbHidden + vbSystem)
For i = 1 To UBound(files)
'update your database passing files(i) as a parameter
Debug.Print files(i)
Next
End Sub

Or you could use the FSO but you can't use wildcards to filter file names.

Function GetFilesFSO(folderpath As String, extension As String)
Dim fso As New Scripting.FileSystemObject, fil As Scripting.File
For Each fil In fso.GetFolder(folderpath).Files
If UCase$(fso.GetExtensionName(fil.path)) = extension Then
'Call a procedure to update your database passing file.
End If
Next
End Function

Oh, you need to add a reference to the Microsoft Scripting Library to use the latter approach.
Hope this helps. :)

Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top