FilesIn + FilesIn_Count

Returns list of files found in a folder, list separated with custom separator
And FilesIn_Count to return number of files
Using Dir not FSO

Function FilesIn(Optional FileMask = "*.*", Optional InFolder = "", Optional Attr = 0, Optional Sepa = "|")
Retu = ""
On Error GoTo ByeBye
di = Dir(FixPath(InFolder) & FileMask, Attr)
Do Until di = ""
If di = "." Or di = ".." Then GoTo 300
If Retu > "" Then Retu = Retu & Sepa
Retu = Retu & di
300:
di = Dir
Loop
ByeBye:
On Error GoTo 0
FilesIn = Retu
End Function

Function FilesIn_Count(Optional FileMask = "*.*", Optional InFolder = "", Optional Attr = 0, Optional Sepa = "|")
 Retu = 0
 On Error GoTo ByeBye
 di = Dir(FixPath(InFolder) & FileMask, Attr)
 Do Until di = ""
  If di = "." Or di = ".." Then GoTo 300
  Retu = Retu + 1
300:
  di = Dir
 Loop
ByeBye:
 On Error GoTo 0
 FilesIn_Count = Retu
End Function

FileMask, InFolder, Attr, Sepa

Views 1711 Downloads 794


ANmarAmdeen
590
File System VBA-Excel
Revisions

v1.0

Tags