The code is a combination of:
- Getting current directory in VBScript
- https://www.go4expert.com/articles/list-files-folder-using-vbscript-t927/
The code below can be stored in a .vbs
file. It first gets the current directory of the (executing) script, and then it gets the list of files that are inside that directory, returns it and finally it prints the first element.
' Get the path of the current (executing) script
scriptdir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
msgbox(scriptdir)
' get file list array
Set fileList = listFiles(scriptdir)
' display first element of file list array
msgbox(fileList(0))
On Error Resume Next
Function listFiles(sFolder)
Set fileList = CreateObject("System.Collections.ArrayList")
Dim fso, folder, files, NewsFile
msgbox(sFolder)
Set fso = CreateObject("Scripting.FileSystemObject")
If sFolder = "" Then
Wscript.Echo "No Folder parameter was passed"
Wscript.Quit
End If
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
For each folderIdx In files
fileList.add(folderIdx.Name)
Next
Set listFiles = fileList
End Function