boblite2 0 Newbie Poster

I found that the following shell code worked for producing a list of all files in the directory and subdirectories of a program I am working on.

The basic lesson I learned is not to try shelling out of VB6 to invoke a batch file containing a list of DOS commands, but instead to issue each DOS command as a separate statement from within VB.

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Private Const SW_SHOWNORMAL = 1


Sub Form_Load()
    'ShellExecute App.Path & "\" & "dir > dirlist /s /b /on /og"  Did not work left the dos window open 
    ShellExecute Me.hwnd, vbNullString, App.Path & "\" & "dir > dirlist /s /b /on /og", vbNullString, "C:\", SW_SHOWNORMAL
    ShellExecute Me.hwnd, vbNullString, App.Path & "\" & "exit", vbNullString, "C:\", SW_SHOWNORMAL
End Sub