Subject: Dir$ problem - not consistent
In order to make the Dir$-function work correctly, the external zip-process must be finished before Your code continues to execute - otherwise Dir$() will fail.
This script gives You the option to run an external process and have Your script wait for it to be finished:
Option Public
Option Explicit
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Public Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Long
cbReserved2 As Long
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadID As Long
End Type
Declare Function CreateProcessA Lib “kernel32” (Byval lpAppName As Long, Byval lpCommandLine As String, Byval lpProcessAttributes As Long, Byval lpThreadAttributes As Long, Byval bInheritHandles As Long, Byval dwCreationFlags As Long, Byval lpEnvironment As Long, Byval lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function WaitForSingleObject Lib “kernel32” (Byval hHandle As Long, Byval dwMilliseconds As Long) As Long
Declare Function CloseHandle Lib “kernel32” (Byval hObject As Long) As Long
Public Sub RunProcess(Byval strCommand As String)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim r As Long
'Initialize the STARTUPINFO structure by
'passing to start the size of the STARTUPINFO
'type. Setting the .cb member is the only
'item of the structure needed to launch the program
start.cb = Len(start)
'Start the application
Call CreateProcessA(0&, strCommand, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'Wait for the application to finish
Call WaitForSingleObject(proc.hProcess, INFINITE)
'Close the handle to the process
Call CloseHandle(proc.hProcess)
'Close the handle to the thread created
Call CloseHandle(proc.hThread)
End Sub
’ — CODE END —
So, all You have to do now is to call the sub with RunProcess(“C:\WINNT\Notepad.exe”) or whatever external process you want to start and Your script will halt until the external process has been closed.
hth