I need to display list of files (better with date and size). I found solution using internal DIR command (see part below), but I would prefer "clear VBS" solution. I don't know how to test that any file exist. Script may run under many locals (English, Czech, French, ...) so I can not test string "File not found".
Const ForReading = 1
Const TemporaryFolder = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSourceFile = strSourcePath & strFileMask
Call EchoTime("List of files " & strSourceFile & " :")
Set objTEMPDir = objFSO.GetSpecialFolder(TemporaryFolder)
strTEMPFile = objFSO.GetTempName
strTEMPFile = objTEMPDir.Path & "\" & strTEMPFile
' List files using redirestion to temporary file
' /U = create file in UNICODE
objShell.Run "cmd /U /C dir " & strSourceFile & " > " & strTEMPFile, 2, True
' Copy output to stdOutput
' False = dont't create when does not exist
' vbTrue = open in UNICODE
Set objTEMPFile = objFSO.OpenTextFile(strTEMPFile, ForReading, False, vbTrue)
WScript.Echo objTEMPFile.ReadAll
objTEMPFile.Close
I used CMD because I know, that this script will run under W2K or W2K3.