Ask Your Question

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

asked 2013-05-12 09:02:10 +0200

Markeee gravatar image

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.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2015-10-31 21:46:39.854641


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

mahfiaz gravatar imagemahfiaz ( 2013-05-13 12:02:40 +0200 )edit

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

JohnSUN gravatar imageJohnSUN ( 2013-05-13 17:14:07 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2013-05-14 11:48:35 +0200

JohnSUN gravatar image

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
edit flag offensive delete link more

Question Tools


Asked: 2013-05-12 09:02:10 +0200

Seen: 1,494 times

Last updated: May 14 '13