stopping a batch file when an error occurs?

  • Thread starter Thread starter yawnmoth
  • Start date Start date
Y

yawnmoth

Say I have the following *.cmd file:

@echo off

cd some_directory
cd ..

If I run it and some_directory exists, nothing will happen - I'll be
in the same directory as before. If, however, some_directory doesn't
exist, it'll take me back to the parent directory.

My question is.. how can I change this behavior? How can I make it
so that if some_directory doesn't exist, it doesn't do "cd .."? Maybe
I could do some sort of if statement and do the "cd .." conditionally?
 
yawnmoth said:
Say I have the following *.cmd file:

@echo off

cd some_directory
cd ..

If I run it and some_directory exists, nothing will happen - I'll be
in the same directory as before. If, however, some_directory doesn't
exist, it'll take me back to the parent directory.

My question is.. how can I change this behavior? How can I make it
so that if some_directory doesn't exist, it doesn't do "cd .."? Maybe
I could do some sort of if statement and do the "cd .." conditionally?

IF ERRORLEVEL...
 
Say I have the following *.cmd file:

@echo off

cd some_directory
cd ..

If I run it and some_directory exists, nothing will happen - I'll be
in the same directory as before. If, however, some_directory doesn't
exist, it'll take me back to the parent directory.

My question is.. how can I change this behavior? How can I make it
so that if some_directory doesn't exist, it doesn't do "cd .."? Maybe
I could do some sort of if statement and do the "cd .." conditionally?




IF Exist C:\some_directory (

echo yes

) ELSE (

echo no
)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top