[AccessD] Grab filenames

John Ruff papparuff at attbi.com
Mon May 19 12:25:49 CDT 2003


Grab filenamesRoz - Will this work for you?

Private Sub cmdFileObject_Click()
' Provides the user Path, File Name,
' and File Size
' Insure there is a reference to the
' Microsoft Scripting Runtime
' Access 2000/2002
    On Error GoTo cmdFileObject_ERR

    Dim fso As FileSystemObject
    Dim f1 As File
    Dim strPathAndFileName As String
    Dim strFileNameOnly As String
    Dim strFileSize As String
    Dim I As Double

    Set fso = CreateObject("Scripting.FileSystemObject")

    With Application.FileSearch
        .NewSearch
        .LookIn = "d:\"
        .FileName = "*.ini"
        .MatchTextExactly = False
        .FileType = msoFileTypeAllFiles
        .SearchSubFolders = True

        If .Execute() > 0 Then
            For I = 1 To .FoundFiles.Count
                DoEvents
                ' File name and its path
                strPathAndFileName = .FoundFiles(I)
                Set f1 = fso.GetFile(.FoundFiles(I))
                strFileSize = f1.Size
                ' File name only
                strFileNameOnly = f1.Name
            Next I
            MsgBox "Done"
        Else
            MsgBox "No Files Found"
        End If
    End With


cmdFileObject_EXIT:

    Exit Sub

cmdFileObject_ERR:

    If Err.Number = 70 Then ' Permission denied
        Resume Next
    End If
    MsgBox Error$

End Sub

John V. Ruff - The Eternal Optimist J


"Commit to the Lord whatever you do,
                and your plans will succeed." Proverbs 16:3

  -----Original Message-----
  From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Roz Clarke
  Sent: Monday, May 19, 2003 7:54 AM
  To: 'accessd at databaseadvisors.com'
  Subject: [AccessD] Grab filenames


  Hi all

  Does anyone have a code snippet for pulling file search results into
Access?

  What I want is to pull the filename, path & size of all files of a given
type on a particular drive, including those in subfolders, into a table. I
need to do it *fast*!!!

  TIA

  Roz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030519/4cdc2bbd/attachment-0001.html>


More information about the AccessD mailing list