Tables
Formulaires
Automation
Administration
Envoyer un mail
Outlook
Dates - Heures
Fichiers
Références
La normalisation
VBA
992295 visiteurs
1 visiteur en ligne
Pour cela, on peut utiliser la fonction suivante qui sauvera le nom des fichiers ainsi que leur taille. Optionnellement, on peut décider de sauver ou non, tous les sous-répertoires et leurs fichiers.
On aura au préalable créé une table composée d'un champ numérique (numéroauto en clé primaire), un champ texte (255 caractères) et un champ numérique (long entier).
Function Dir2Table(strDir As String, strTable As String, _ strFieldName As String, strFieldLength As String, _ Optional boSubFolder As Boolean = False) Dim intFile As Integer Dim strFile As String Dim lngSize As Long intFile = 0: strFile = "" With Application.FileSearch .SearchSubFolders = boSubFolder .FileType = msoFileTypeAllFiles .LookIn = strDir If .Execute(SortBy:=msoSortBySize, _ SortOrder:=msoSortOrderDescending) > 0 Then For intFile = 1 To .FoundFiles.Count strFile = .FoundFiles(intFile) '/ Pour des ko, on divisera par 1024 'lngSize = FileLen(strFile) / 1024 lngSize = FileLen(strFile) strFile = Mid(strFile, InStrRev(strFile, Chr(92)) + 1) CurrentDb.Execute "INSERT INTO [" & strTable & "] " _ & "([" & strFieldName & "]," _ & "[" & strFieldLength & "])" _ & "SELECT """ & strFile & """," _ & lngSize & ";" Next End If End With End Function