OUTPUT
Example:
AllFiles =GetFileNamesfromFolder("c:\")
msgbox AllFiles
msgbox Replace(AllFiles,",",vbcrlf)
OUTPUT
=======
All file names in comma seperated format
Further:
you can use split to spilt all names into array
AllFiles =GetFileNamesfromFolder("c:\") ArrayOfFiles = Split(AllFiles,",")
Function GetFileNamesfromFolder(sFolder) Dim filenames Dim fso, folder,files Dim firstfile On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set folder = fso.GetFolder(sFolder) Set files = folder.Files firstfile =true For each folderIdx In files if firstfile then filenames =folderIdx.Name firstfile =false else filenames = filenames & "," & folderIdx.Name End If 'msgbox filenames Next GetFileNamesfromFolder=filenames End Function
Example:
AllFiles =GetFileNamesfromFolder("c:\")
msgbox AllFiles
msgbox Replace(AllFiles,",",vbcrlf)
OUTPUT
=======
All file names in comma seperated format
Further:
you can use split to spilt all names into array
AllFiles =GetFileNamesfromFolder("c:\") ArrayOfFiles = Split(AllFiles,",")