1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
Function GetSpecificFile(strParentFolderPath, strFileNameFirstChars, strFileExtension)
Dim objFso, objParentFolderPath, objTmpFile, strTmpFileName
Set objFso = CreateObject("Scripting.FileSystemObject")
GetSpecificFile = ""
If NOT objFso.FolderExists(strParentFolderPath) Then Exit Function
If StrComp(Left(strFileExtension, 1), ".") <> 0 Then strFileExtension = "." & strFileExtension
Set objParentFolderPath = objFso.GetFolder(objParentFolderPath)
For Each objTmpFile In objParentFolderPath.Files
strTmpFileName = objTmpFile.Name
If StrComp (Left(strTmpFileName, Len(strFileNameFirstChars)), strFileNameFirstChars, vbTextCompare) <> 0 _
And StrComp (Right(strTmpFileName, Len(strFileExtension)), strFileExtension, vbTextCompare) <> 0 Then _
GetSpecificFile = strTmpFileName & ";"
Next
If Len(GetSpecificFile) > 0 Then GetSpecificFile = Left(GetSpecificFile, Len(GetSpecificFile) -1)
End Function
' Utilisation
Dim strArrFiles , strFilePath
strArrFiles = GetSpecificFile("C:\Tmp\", "EBL", ".txt")
For Each strFilePath In Split(strArrFiles, "|")
'Traitement du fichier
Next |
Partager