Page 1 of 1

Windows 7 "If Exist" Error.

Posted: 29 Jan 2010 17:29
by BAT Beginner
I try using
if exist
or
if not exist
on my new Win7 64-bit computer.
Unfortunently, I think they changed the code up, and I really need the code for If Exist in Windows 7 batch Files.
~BAT Beginner

Re: Windows 7 "If Exist" Error.

Posted: 29 Jan 2010 17:37
by aGerman
Hi BAT Beginner,

I don't believe that the syntax is changed. Would you show us the entire line or code?

Regards
aGerman

Re: Windows 7 "If Exist" Error.

Posted: 29 Jan 2010 17:50
by BAT Beginner

Code: Select all

@echo off
if exist help.txt
goto yes
if not exist help.txt
goto no
:yes
Echo You Do have help.txt in this folder.
pause
:no
Echo You Do not have help.txt in this folder.
pause

Re: Windows 7 "If Exist" Error.

Posted: 29 Jan 2010 17:57
by aGerman
You have to use it in one line with the command that should be executed.
For your example:

Code: Select all

@echo off &setlocal
if not exist help.txt goto no

Echo You Do have help.txt in this folder.
pause
goto :eof

:no
Echo You Do not have help.txt in this folder.
pause


Regards
aGerman

Re: Windows 7 "If Exist" Error.

Posted: 29 Jan 2010 20:54
by BAT Beginner
Thank you So Much!
You are so Helpful!
~BAT Beginner