Examining the contents of a folder in Acess 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Walter Konopacki
    New Member
    • Feb 2008
    • 8

    Examining the contents of a folder in Acess 2003

    Need to get a list of jpeg files in a folder in order to create a one to one set of records in a table.
  • sierra7
    Recognized Expert Contributor
    • Sep 2007
    • 446

    #2
    Hi
    You will need to use the Dir() function recursively.
    [CODE=vb] Dim strNextFile As String
    Dim strPath as String

    'set path to folder and to look for jpg files
    strPath = "C:\MyFolder\*. jpg"

    'initialise Dir() function and get first filename
    strNextFile = Dir(strPath, vbNormal)

    'turn off warnings
    Application.Set Option "Confirm Action Queries", False

    'now loop using the Dir function until no more files found
    Do While strNextFile <> ""

    'insert filename into table tblJPES
    DoCmd.RunSQL "INSERT INTO tblJPEGS (FilNam) Values (" & strNextFile & ");"

    'now call Dir recursively
    strNextFile = Dir
    Loop

    'turn warnings on
    Application.Set Option "Confirm Action Queries", False
    [/CODE]

    I have assumed the file names will be written to field FilNam in table tblJPEGS.

    Hope this helps

    S7

    Comment

    • Walter Konopacki
      New Member
      • Feb 2008
      • 8

      #3
      Thanks Sierra7, was wondering if I would get a reply. Greatly Appreciated !

      Comment

      • sierra7
        Recognized Expert Contributor
        • Sep 2007
        • 446

        #4
        [
        Your welcome.

        There are other ways to save the retrieved data using Recordsets and the like but I think that looping through the files of the folder and reading the contents is the issue here.

        Good luck with the rest of your program.

        S7

        Comment

        Working...