Results 1 to 4 of 4

Thread: Writing a filename to a database!!! Please Help!!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Question

    I have a load of file in a directory. How do I write all of the file names that are contained in that folder and all subfolders to a database table. Thanks for any help that anyone may be able to offer.

  2. #2
    Lively Member
    Join Date
    Nov 2000
    Posts
    73

    Smile

    hi,
    add a filelist box control and try this code

    Dim ictr As Integer
    File1.Path = App.Path
    For ictr = 0 To File1.ListCount - 1
    MsgBox File1.List(ictr)
    'update ur field with this code
    'filedname = file1.list(ictr)
    Next ictr

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    You can use the Dir command to loop through a directory listing. This will return a string representing the file name. If you check the attributes, you can decide which are sub-directories and recurese into those (i.e. pick up sub-directories of sub-directories).

    Check out Dir() in VB Help, there are some good examples.

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    [code[
    Option Explicit

    Private Sub Command1_Click()
    Dim myDir As String
    myDir = "C:\AWay"
    Call ProcessDir(myDir)
    End Sub

    Public Sub ProcessFiles(d As String)
    List1.AddItem d
    End Sub

    Public Sub ProcessDir(strDir As String)
    Dim i
    Dim iCount As Integer
    Dim FileList() As String
    Dim Result As String

    iCount = 0
    Result = Dir(strDir & "\*.*", vbDirectory)
    Do While Result <> "" ' Start the loop.
    If Result <> "." And Result <> ".." Then
    iCount = iCount + 1
    ReDim Preserve FileList(1 To iCount)
    FileList(iCount) = strDir & "\" & Result
    End If
    Result = Dir
    Loop

    ' For i = 1 To iCount
    For i = LBound(FileList) To UBound(FileList)
    If (GetAttr(FileList(i)) And vbDirectory) = vbDirectory Then
    ProcessDir (FileList(i))
    Else
    ProcessFiles (FileList(i))
    End If ' it represents a directory.
    Next

    End Sub
    [/code]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width