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!

if text file empty then stop, else run program

Status
Not open for further replies.

lfrazier

Technical User
Apr 16, 2002
8
US
Hello script gurus,

I need to check:

IF a text file is empty, then end the script.

ELSE run program with a switch.

example: Else "merge.exe filename.txt"

Is that possible in VBScript?



Lloyd F.
Labor Analytics Consultant
 
[tt]'your givens[green]
sfile="filename.txt" 'with path if needed.
scmd="merger.exe " & sfile 'with the necessary path setting[/green]

dim fso
set fso=createobject("scripting.filesystemobject")
if fso.fileexists(sfile) then
if fso.getfile(sfile).size<>0 then
createobject("wscript.shell").run scmd
else
wscript.echo sfile & " has the size of 0. Action not taken."
end if
else
wscript.echo sfile & " cannot be found."
end if
set fso=nothing
[/tt]
 
tsuji,

thanks for the terrific script.

Is there a way to suppress the success message?

I tried messing with what you had but I cannot get it right.

If the file is blank, I just want the script to end with no pop up message.



Lloyd F.
Labor Analytics Consultant
 
Replace the two wscript.echo lines with:
WScript.Quit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Just comment them out. I put there for your own sake, it is up to be changed to your liking.
 
tsuji,

it is a thing of beauty.

Thank your for your assistance.


Lloyd F.
Labor Analytics Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top