Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

rechercher fichier ds repertoire ...

2 réponses
Avatar
FTH
Bonjour,

Le code ci-dessous me permet de rechercher les fichiers dans un repertoire
et de remplir une table avec le path et le nom de fichier. (merci au forum!)
dans la pratique, de nouveaux fichiers sont parfois creer, d'autre sont
effacés.
Comment mettre une conditions au remplissage de la table?

Si [path] & [fichier] existe dans la table, ne pas remplir;
si [path] & [fichier] n'existe pas dans la table, remplir la table

d'avance merci,

Frédéric


Function FileExistDir2(strDir As String, strTable As String)
Dim rst As DAO.Recordset
Dim intFile As Integer, cpt As Long
Dim strFile As String, strPath As String
intFile = 0: strFile = ""
Set rst = CurrentDb.OpenRecordset(strTable)
With Application.FileSearch
.SearchSubFolders = True
.LookIn = strDir: .FileName = "*.*"
If .Execute > 0 Then
For intFile = 1 To .FoundFiles.Count
strFile = .FoundFiles(intFile)
strPath = Left(strFile, InStrRev(strFile, "\"))
strFile = Right(strFile, Len(strFile) - InStrRev(strFile,
"\"))
rst.AddNew
rst!PathDoc = strPath
rst!NameDoc = strFile
rst.Update
cpt = cpt + 1
Next
End If
End With
MsgBox cpt & " records in this table " & strTable
rst.Close
Set rst = Nothing
End Function

2 réponses

Avatar
Fabien
Bonjour,

Le code ci-dessous me permet de rechercher les fichiers dans un
repertoire et de remplir une table avec le path et le nom de fichier.
(merci au forum!)
dans la pratique, de nouveaux fichiers sont parfois creer, d'autre sont
effacés.
Comment mettre une conditions au remplissage de la table?

Si [path] & [fichier] existe dans la table, ne pas remplir;
si [path] & [fichier] n'existe pas dans la table, remplir la table

d'avance merci,

Frédéric


Function FileExistDir2(strDir As String, strTable As String)
Dim rst As DAO.Recordset
Dim intFile As Integer, cpt As Long
Dim strFile As String, strPath As String
intFile = 0: strFile = ""
Set rst = CurrentDb.OpenRecordset(strTable)
With Application.FileSearch
.SearchSubFolders = True
.LookIn = strDir: .FileName = "*.*"
If .Execute > 0 Then
For intFile = 1 To .FoundFiles.Count
strFile = .FoundFiles(intFile)
strPath = Left(strFile, InStrRev(strFile, ""))
strFile = Right(strFile, Len(strFile) -
InStrRev(strFile, ""))
rst.AddNew
rst!PathDoc = strPath
rst!NameDoc = strFile
rst.Update
cpt = cpt + 1
Next
End If
End With
MsgBox cpt & " records in this table " & strTable
rst.Close
Set rst = Nothing
End Function


Salut,
En testant par un dcount la présence de ton fichier dans la table ....
If .Execute > 0 Then
For intFile = 1 To .FoundFiles.Count
strFile = .FoundFiles(intFile)
strPath = Left(strFile, InStrRev(strFile, ""))
strFile = Right(strFile, Len(strFile) -
InStrRev(strFile, ""))
If Dcount("*",Strtable,"[NameDoc]='" & StrFile & "'")=0 then

rst.AddNew
rst!PathDoc = strPath
rst!NameDoc = strFile
rst.Update
cpt = cpt + 1
end if

Next


Avatar
Fabien
Bonjour,

Le code ci-dessous me permet de rechercher les fichiers dans un
repertoire et de remplir une table avec le path et le nom de fichier.
(merci au forum!)
dans la pratique, de nouveaux fichiers sont parfois creer, d'autre
sont effacés.
Comment mettre une conditions au remplissage de la table?

Si [path] & [fichier] existe dans la table, ne pas remplir;
si [path] & [fichier] n'existe pas dans la table, remplir la table

d'avance merci,

Frédéric


Function FileExistDir2(strDir As String, strTable As String)
Dim rst As DAO.Recordset
Dim intFile As Integer, cpt As Long
Dim strFile As String, strPath As String
intFile = 0: strFile = ""
Set rst = CurrentDb.OpenRecordset(strTable)
With Application.FileSearch
.SearchSubFolders = True
.LookIn = strDir: .FileName = "*.*"
If .Execute > 0 Then
For intFile = 1 To .FoundFiles.Count
strFile = .FoundFiles(intFile)
strPath = Left(strFile, InStrRev(strFile, ""))
strFile = Right(strFile, Len(strFile) -
InStrRev(strFile, ""))
rst.AddNew
rst!PathDoc = strPath
rst!NameDoc = strFile
rst.Update
cpt = cpt + 1
Next
End If
End With
MsgBox cpt & " records in this table " & strTable
rst.Close
Set rst = Nothing
End Function


Salut,
En testant par un dcount la présence de ton fichier dans la table ....
If .Execute > 0 Then
For intFile = 1 To .FoundFiles.Count
strFile = .FoundFiles(intFile)
strPath = Left(strFile, InStrRev(strFile, ""))
strFile = Right(strFile, Len(strFile) -
InStrRev(strFile, ""))
If Dcount("*",Strtable,"[NameDoc]='" & StrFile & "'")=0 then

rst.AddNew
rst!PathDoc = strPath
rst!NameDoc = strFile
rst.Update
cpt = cpt + 1
end if

Next
Petit complément ...


If Dcount("*",StrTable,"[NameDoc]='" & StrFile & "' and [PathDoc]='" &
StrPath & "'")=0 then
;-)