Windows/DOS batch files: a couple of hints

Sometimes even Windows needs scripting, and if the script it’s quite simple you can use the old DOS batch files, although it may be harder than you expect to get it right.

For example, when using the IF…ELSE construct, the indentention is quite picky, and you HAVE TO put the ELSE right behind the IF parethesis


IF EXIST filename (
echo "Filename exists"
) ELSE (
echo "Filename doesn't exist"
)

because otherwise it will break your script. For example, this batch file DOESN’T WORK:


IF EXIST filename (
echo "Filename exists"
)
ELSE (
echo "Filename doesn't exist"
)

and always remember to preput

@echo off

if you don’t want let Windows output your script on the terminal output.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s