Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Suppress DOS box flashing

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,

I would like to make a list of all files in all subdirectories with their fullpath and had therefore constructed
Code:
tcSourceFile = "D:\Foxexamples\Backup"
tcDestinationFile = "C:\Temp\Files.txt"
lcCmd = "DIR "+ tcSourceFile+ "/s /b /a-d > " + tcDestinationfile

loShell = Createobject("wscript.shell")
lnSuccess = m.loShell.Run(m.lcCmd,1,.T.)
If m.lnSuccess = 0
	=Messagebox("list successful.",0+64,"Make a list!")
Else
	=Messagebox("List failed",0+16,"Caution")
Endif
Which works fine, but how to suppress the DOS-Box flashing?

Regards,
Koen
 
You can use the .Run , 0 to hide the window like:

Code:
Set objShell = WScript.CreateObject("WScript.Shell")
isHidden = 0 'change 0 to 1 to show the CMD prompt
objShell.Run "%comspec% /c myfile.bat", isHidden


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Hi,

Sorry,
my question was not clear / not correct.

The line
Code:
RUN DIR d:\foxexamples\backup /s /b /a-d > c:\temp\files5.txt
works like a charm, now to suppress the DosBox flashing I had constructed:

Code:
loShell = Createobject("wscript.shell")
lnSuccess = m.loShell.Run(m.lcCmd,0,.T.)
If m.lnSuccess = 0
	=Messagebox("list successful.",0+64,"Make a list!")
Else
	=Messagebox("List failed",0+16,"Caution")
Endif 
return

This code errors: OLE Error 0x80070002 The system can not find the given object.

@ Griff,

I suppose your code was not for VFP as it errors already on the 1st line SET etc.

Regards,

Koen
 
I was just trying to point you in the right direction, using the parameters to suppress the box, rather than a cut and paste job for you.

If your original code worked, I would use this (and you could cut and paste it)

Code:
tcSourceFile = "D:\Foxexamples\Backup"
tcDestinationFile = "C:\Temp\Files.txt"
lcCmd = 'DIR "'+ tcSourceFile+ '"/s /b /a-d > "' + tcDestinationfile +'"'

loShell = Createobject("wscript.shell")
lnSuccess = m.loShell.Run(m.lcCmd,0,.T.)
If m.lnSuccess = 0
	=Messagebox("list successful.",0+64,"Make a list!")
Else
	=Messagebox("List failed",0+16,"Caution")
Endif

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
The problem is that it is looking for an actual file named DIR. I think you need something like this:

Code:
lcCmd = "[highlight #EDD400]command.com[/highlight] DIR "+ tcSourceFile+ "/s /b /a-d > " + tcDestinationfile

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,
The code as advised by Griff and the solution advised from Mike both resulted in the error 'OLE Error 0x80070002 The system can not find the given object.'.
Koen
 
That's curious.

Do you know which line number generated this error, I would guess it was the call to
Code:
loShell = Createobject("wscript.shell")

Which would imply the scripting shell is not installed or not available at run-time.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
If you can't run wscript.shell the foxrun.pif settings are a chance to suppress the DOS screen or read the last paragraph of the help topic on RUN and use ShellExectuteEx or ShellExecute API call instead:

Code:
#DEFINE HIDEWINDOW 0

DECLARE INTEGER ShellExecute IN shell32.dll ; 
  INTEGER hndWin, ; 
  STRING cAction, ; 
  STRING cFileName, ; 
  STRING cParams, ;  
  STRING cDir, ; 
  INTEGER nShowWin
  
  
cAction = "open" 
cFileName = GetEnv("ComSpec")
cParams = [/k "DIR C:\ >C:\temp\files.txt"]
lnResult = ShellExecute(0,cAction,cFileName,cParams,"",HIDEWINDOW)

As usual, a result <42 is an error. The meaning of it can be retrieved by GetLastError API call, but you may also look that up in header files: Microsoft Docs: System Error Codes (0-499)

Bye, Olaf.

Olaf Doschke Software Engineering
 
Griff,
the error occurs at line
Code:
lnSuccess = m.loShell.Run(m.lcCmd,0,.T.)

@Olaf,
I am missing the destinationfile or sourcefile parameter with its parameters "/s /b /a-d > " and unfortunately cant figure out how to implent in your solution since the url given by you gives an error 404.

Sorry guys, this is taking much too much time, most interesting to solve, but meanwhile I will go on with a pure VFP solution, al lot more coding but that I am able to make it work as I would like.
The aim is to construct a text file with all the files and files in the subdirectories with full path in a text file.
With afiles and a recursive it can be solved.

Koen
 
I wrte a FAQfor that (about 12 years ago!)
faq184-6312

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Koen, I fixed the link, but the code also was missing a = sign at the last line.

You would add your command into the cParams value, the general pattern is that you call cmd.exe with parameter /k and the DOS command you useually would write after RUN in quotes, so:

Code:
#DEFINE HIDEWINDOW 0

DECLARE INTEGER ShellExecute IN shell32.dll ; 
  INTEGER hndWin, ; 
  STRING cAction, ; 
  STRING cFileName, ; 
  STRING cParams, ;  
  STRING cDir, ; 
  INTEGER nShowWin
  
lcCmd = "your command, however and whatever you put together"
  
cAction = "open" 
cFileName = GetEnv("ComSpec")
cParams = [/k "]+lcCmd+["]
lnResult = ShellExecute(0,cAction,cFileName,cParams,"",HIDEWINDOW)

The way this works is doing what RUN normally does. The DOS command is a parameter to cmd.exe And it's parameter /k means not just starting a DOS shell waiting for a command, but executing a line of code. So all this does is reimplement the RUN command with the ability to control how the DOS window shows, or doesn't show in the last ShellExecute parameter.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Koen,

I know this thread is quite old now, but I was wondering if you found a good solution.

The reason I ask is that I had a similar requirement today, that is, to send a list of filenames in a given folder to a text file. I did it like this:

[tt]DIR D:\Foxexamples\Backup\*.* TO FILE C:\Temp\Files.txt[/tt]

This just gives a straight list of filenames. If you want also to show filesize, modification date, etc., you could do it by using ADIR() to get that information into an array, hten looping through the array, writing each line of information to your file.

Does that help at all?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
That is funny, I was looking for the possibility to create such a txt file since I wanted to make a cab file - backup. The instruction:
Code:
lcCmd = "DIR "+ tcSourceFile+ "/s /b /a-d > " + tcDestinationfile
constructed a nice txtfile with the fullpath of each file on a row. Good to be used to create a cab file.
I than searched for the possibility to do this, fast dos cmd, in VFP without the flashing box.
Several advises took me a full day and did not result in the required effect.
I than left the idea to use the DOS and constructed with a recursive adir() the txt file with the ness layout to be used for my cab command.
Now I have a full VFP code constructing this txt file, n-times bigger than the simple DOS command and a little bit slower.
I am 95% satisfied.
Thanks for your suggestion.
Regards,
Koen



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top