Jump to content

stopping a batch file when an error occurs?


Recommended Posts

Guest yawnmoth
Posted

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?

  • Replies 2
  • Created
  • Last Reply
Guest HeyBub
Posted

Re: stopping a batch file when an error occurs?

 

yawnmoth wrote:

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

Guest spamsucks@tiscali.co.uk
Posted

Re: stopping a batch file when an error occurs?

 

On 26 Aug, 06:45, yawnmoth <terra1...@yahoo.com> wrote:

> 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

)


×
×
  • Create New...