Results 1 to 2 of 2
  1. #1
    RemoteRobot is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Location
    Indiana, USA
    Posts
    4

    Directory Listing

    I am in need of a code which would return the file names from a directory into a table. The returned information would look something like this:



    tblCurrentFiles
    FileName
    FileDate
    FileSize
    FileDirectory

    Preferably it could pull from a list of directories stored in a table.
    tblCurrentDirectories
    DirectoryLocation

    I would assume this would be written in VBA. I am a novice to this and would welcome assistance.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    USAGE : ImportAllFilesIn1Dir( [FOLDER NAME] )

    Code:
    '-----------------
    Public Sub ImportAllFilesIn1Dir(ByVal pvDir)
    '-----------------
    Dim pvName, vTargT, vDate, vSize
    Dim i As Integer
    Dim sTbl As String, sSql As String
    Dim fso
    Dim oFolder, oFile
    
    'On Error GoTo errImp
    If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
    
    DoCmd.SetWarnings False
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder(pvDir)
    For Each oFile In oFolder.Files
        vName = oFile.Name
        vDate = oFile.DateLastModified
        vSize = oFile.Size
        
         sSql = "Insert into tblCurrentFiles ( Filename, FileDate, FileSize, FileDirectory) values ('" & vName & "','" & vDate & "'," & vSize & ",'" & pvDir & "')"
        DoCmd.RunSQL sSql
    Next
    
    Set fso = Nothing
    Set oFile = Nothing
    Set oFolder = Nothing
    DoCmd.SetWarnings True
    MsgBox "Done"
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 08-06-2019, 07:16 PM
  2. Job listing
    By UT227 in forum Queries
    Replies: 5
    Last Post: 02-15-2018, 12:46 PM
  3. Replies: 6
    Last Post: 10-26-2012, 12:53 PM
  4. Replies: 3
    Last Post: 03-23-2012, 06:16 AM
  5. Replies: 6
    Last Post: 06-15-2011, 04:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums