devxlogo

Redirecting DIR Command Output

Redirecting DIR Command Output

Question:
How do I create the VB equivalent of the command below

DIR C: /S /B >MYFILE.LST
I need this routine for a program that keeps track of installedand removed files.

Answer:
Try:

Shell “COMMAND.COM /C DIR C: /S /B > MYFILE.LST”
That should do what you want it to. DIR is not a program…it is part of the command interpreter.Be aware that you can write a routine in straight VB code that will do this without shelling to DOS. Look in help for the Dir Function (I believe it’s called Dir$ in VB3.0).

devx-admin

Share the Post: