×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Suppress DOS box flashing

Suppress DOS box flashing

Suppress DOS box flashing

(OP)
Hi,

I would like to make a list of all files in all subdirectories with their fullpath and had therefore constructed

CODE --> vfp

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

RE: Suppress DOS box flashing

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 Smileing

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.

RE: Suppress DOS box flashing

I think this is just a question of passing zero as the second parameter to the the Run method:

CODE -->

lnSuccess = m.loShell.Run(m.lcCmd, 0, .T.) 

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Suppress DOS box flashing

(OP)
Hi,

Sorry,
my question was not clear / not correct.

The line

CODE --> vfp

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 --> vfp

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

RE: Suppress DOS box flashing

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 Smileing

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.

RE: Suppress DOS box flashing

The problem is that it is looking for an actual file named DIR. I think you need something like this:

CODE -->

lcCmd = "command.com DIR "+ tcSourceFile+ "/s /b /a-d > " + tcDestinationfile 

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Suppress DOS box flashing

(OP)
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

RE: Suppress DOS box flashing

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 Smileing

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.

RE: Suppress DOS box flashing

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
https://www.doschke.name

RE: Suppress DOS box flashing

(OP)
Griff,
the error occurs at line

CODE --> vfp

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

RE: Suppress DOS box flashing

I wrte a FAQfor that (about 12 years ago!)
FAQ184-6312: Search Folders & SubFolders for Files

Regards

Griff
Keep Smileing

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.

RE: Suppress DOS box flashing

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
https://www.doschke.name

RE: Suppress DOS box flashing

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:

DIR D:\Foxexamples\Backup\*.* TO FILE C:\Temp\Files.txt

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

RE: Suppress DOS box flashing

(OP)
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 --> vfp

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



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close