_Title "Windows Dir FileList" ' b+ 2022-01-31
ReDim FileList$
(1 To 1) ' to call DirFiles with array name to load with files DirFiles FileList$() 'try the directory above current
Sub DirFiles
(FileList$
()) a$ = pipecom_lite$("DIR *.* /a:-d /b /o:-gen")
Split a$
, Chr$(10), FileList$
()
' note: I buggered this twice now, FOR base 1 array REDIM MyArray (1 to 1) AS ... the (1 to 1) is not same as (1) which was the Blunder!!!
'notes: REDIM the array(0) to be loaded before calling Split '<<<< IMPORTANT dynamic array and empty, can use any lbound though
'This SUB will take a given N delimited string, and delimiter$ and create an array of N+1 strings using the LBOUND of the given dynamic array to load.
'notes: the loadMeArray() needs to be dynamic string array and will not change the LBOUND of the array it is given. rev 2019-08-27
curpos
= 1: arrpos
= LBound(loadMeArray
): LD
= Len(delim
) dpos
= InStr(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = Mid$(SplitMeString
, curpos
, dpos
- curpos
) arrpos = arrpos + 1
curpos = dpos + LD
dpos
= InStr(curpos
, SplitMeString
, delim
) loadMeArray
(arrpos
) = Mid$(SplitMeString
, curpos
)
stdout = "": stderr = ""
As _Unsigned Long dwX
, dwY
, dwXSize
, dwYSize
, dwXCountChars
, dwYCountChars
, dwFillAttribute
, dwFlags
As _Offset lpReserved2
, hStdInput
, hStdOutput
, hStdError
Const STARTF_USESTDHANDLES
= &H00000100 Const CREATE_NO_WINDOW
= &H8000000
Const INFINITE
= 4294967295 Const WAIT_FAILED
= &HFFFFFFFF
Dim As _Offset hStdOutPipeRead
, hStdOutPipeWrite
, hStdReadPipeError
, hStdOutPipeError
Dim As SECURITY_ATTRIBUTES sa: sa.nLength
= Len(sa
): sa.lpSecurityDescriptor
= 0: sa.bInheritHandle
= 1
pipecom = -1
pipecom = -1
si.dwFlags = STARTF_USESTDHANDLES
si.hStdError = hStdOutPipeError
si.hStdOutput = hStdOutPipeWrite
si.hStdInput = 0
Dim As PROCESS_INFORMATION procinfo
Dim As Long bInheritHandles: bInheritHandles
= 1 ok
= CreateProcess
(lpApplicationName
, _Offset(lpCommandLine
), lpProcessAttributes
, lpThreadAttributes
, bInheritHandles
, dwCreationFlags
, lpEnvironment
, lpCurrentDirectory
, _Offset(si
), _Offset(procinfo
))
pipecom = -1
HandleClose hStdOutPipeWrite
HandleClose hStdOutPipeError
buf
= Mid$(buf
, 1, dwRead
) stdout = stdout + buf
buf
= Mid$(buf
, 1, dwRead
) stderr = stderr + buf
If WaitForSingleObject
(procinfo.hProcess
, INFINITE
) <> WAIT_FAILED
Then If GetExitCodeProcess
(procinfo.hProcess
, _Offset(exit_code
)) Then ex_stat = 1
HandleClose hStdOutPipeRead
HandleClose hStdReadPipeError
pipecom = exit_code
pipecom = -1
RemoveChr13:
stream = popen(cmd + " 2>pipestderr", "r")
If fgets
(buffer
, 4096, stream
) <> "" And feof
(stream
) = 0 Then status = pclose(stream)
exit_code = WEXITSTATUS(status)
pipecom = exit_code
pipecom = -1
a = pipecom(cmd, stdout, stderr)
pipecom_lite = stderr
pipecom_lite = stdout