At a command prompt, the command "dir c:/s>filename.out" can be run to
get a list of all the directories, filenames and the file sizes on drive
C: and redirected to a text file. Is there an equivalent way to do this
in Visual Basic?
AK
HTH. Later...
Geert Marttin
-----
"Discontent is the first step in the progress of a man or a nation."
Oscar Wilde
If you are going to supply the filename.out file through a variable and
include the path with it, be aware that DOS is sensitive to blank spaces in
paths or filenames. Enclose the filename variable with extra quotes, like so
(using line continuation to protect against a "funny" break by your news
reader):
Drv = "c:"
FileOut = "filename.out"
Shell Environ("comspec") & " /c dir " & Drv & _
" /s > """ & FileOut &
"""", vbHide
If you will need to use this file inside the same program, then you will
need to wait for the Shell'ed out program to finish. Use the following:
Paste these lines in the (General)(Declarations) section of the form where
the Shell is being called (or remove the Private keywords and put them in a
BAS module if more than one form will use them):
Private Declare Function OpenProcess _
Lib "kernel32" _
(ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle _
Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject _
Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Call your Shell command in this form with the appropriate Shell arguments
placed in the parentheses:
PID = Shell( <<Put Shell Arguments Here>> )
And finally, paste the following IMMEDIATELY after the PID=Shell statement
above (making sure to handle the possible error where indicated; i.e. stop
the code from falling through to your other commands if the Shell failed):
If PID = 0 Then
'
'Handle Error, Shell Didn't Work
'
Else
hProcess = OpenProcess(&H100000, True, PID)
WaitForSingleObject hProcess, -1
CloseHandle hProcess
End If
One note -- there are some NT systems (those with VERY tight security
measures in place) where this call won't work. No problem at all on 95/98
though.
Rick
Julie and Arnold Kay wrote in message <37A541...@worldnet.att.net>...
>Hi,
>
>At a command prompt, the command "dir c:/s>filename.out" can be run to
>get a list of all the directories, filenames and the file sizes on drive
>C: and redirected to a text file. Is there an equivalent way to do this
>in Visual Basic?
>
>AK
Rick
Geert Marttin wrote in message <#bATiXL3#GA.205@cppssbbsa04>...
>Julie and Arnold Kay <J-A...@worldnet.att.net> wrote in message
>news:37A541...@worldnet.att.net...
>> At a command prompt, the command "dir c:/s>filename.out"
>> can be run to get a list of all the directories, filenames and the
>> file sizes on drive C: and redirected to a text file. Is there an
>> equivalent way to do this in Visual Basic?
Drv = "c:"
FileOut = "filename.out"
Shell Environ("comspec") & " /c dir " & Drv & _
" /s > """ & FileOut & """", vbHide
Rick
Rick Rothstein wrote in message ...
>>At a command prompt, the command "dir c:/s>filename.out" can be run to
>>get a list of all the directories, filenames and the file sizes on drive
>>C: and redirected to a text file. Is there an equivalent way to do this
>>in Visual Basic?
>>
>>AK
>
>