How to use Shell with Windows cmd.exe, especially the dir command

How to use Shell with Windows cmd.exe, especially the dir command.

I want to use the dir() run-time command and the Windows dir command, both as a cross-check and in case one will process 100k files and directories
faster than the other.

Could you please make it clear how this is related to LibreOffice? Are you trying to do this using Basic (VBA)?

Do you really think that function ReadDirectories from the standard library Tools (module UCB) worse than the DIR? Just try it…

May be so?

Sub ShellDir
Dim sWhat As String, sWhere As String, sCmd As String
Dim iNum As Integer, iCount As Integer
Dim sLine As String, sMsg As String

sWhat = "D:\ExternalDocs\*.*"
sWhere = "C:\Temp\Dir_Temp.txt"
If FileExists(sWhere) Then Kill sWhere
sCmd =  "/C dir "+sWhat+" /S /B /X >"+sWhere 
REM \\ Run programm cmd.exe with parameters
REM \\ /C dir D:\ExternalDocs\*.* /S /B /X >C:\Temp\Dir_Temp.txt (sCmd)
REM \\ in minimized program window, but focus remains on the active window (6)
REM \\ and wait result (True)
REM \\ Read result:
iNum = FreeFile
Open sWhere For Input As #iNum
iCount = 0
Do While not EOF(iNum)
	Line Input #iNum, sLine
	If sLine <> "" Then iCount = iCount + 1
Close #iNum
If iCount = 0 Then 
	sMsg = "No Files in dir '"+sWhat+"'"
	sMsg = "Found "+iCount+" files/subdirs in dir '"+sWhat+"'"+Chr(13) _
		+"Result in '"+sWhere+"'"
Msgbox sMsg
End Sub
1 Like