Public Sub elencafile(Optional d As String, Optional j As String)
'Autore: Lorenzo Coronati
'Argomenti:
' d=directory
' j=maschera di match
Dim t As TableDef
Dim r As Recordset
Dim s As String
If d = "" Then d = CurDir ' se non specificata usa la dir corrente
If j = "" Then j = "*.*" ' se non specificato, lista tutti i file
If Right(d, 1) <> "\" Then d = d & "\"
s = "Files presenti in " & d
Set t = CurrentDb.CreateTableDef(s)
t.Fields.Append t.CreateField("NomeFile", dbText)
CurrentDb.TableDefs.Append t
Set r = CurrentDb.OpenRecordset(s, dbOpenTable)
s = Dir(d & j)
With r
Do While s <> "" ' cicla per ogni file nella directory
.AddNew
!NomeFile = s
s = Dir
.Update
Loop
End With
End Sub
|