[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Batch/VBscript to check if file exists, if exists run another batch

Posted on 2013-01-23
2
Medium Priority
?
1,341 Views
Last Modified: 2013-01-23
Hello,

I am looking for a batch/vbscript file to check a directory if a file exists, if the file exists, call another batch file.  If it doesn't exist, exit.

Something like "if exist "C:\test.txt" run "c:\runme.bat " ELSE exit"

Can't seem to get the above to work.

Thank you.
0
Comment
Question by:cbones
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 38811427
Close:
if exist "C:\test.txt" (call "c:\runme.bat") ELSE (exit)

Open in new window

0
 
LVL 71

Expert Comment

by:Qlemo
ID: 38811452
The parens are essential, but I won't use    (exit)    , as that closes the cmd window. It is better to use    (exit /b)   to only exit from the current batch file.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question