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
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
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
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
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
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 ;-)
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
;-)
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 ;-)