Windows 7 "If Exist" Error.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BAT Beginner
Posts: 16
Joined: 29 Jan 2010 17:19

Windows 7 "If Exist" Error.

#1 Post by BAT Beginner » 29 Jan 2010 17:29

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Windows 7 "If Exist" Error.

#2 Post by aGerman » 29 Jan 2010 17:37

Hi BAT Beginner,

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

Regards
aGerman
Last edited by aGerman on 29 Jan 2010 17:50, edited 1 time in total.

BAT Beginner
Posts: 16
Joined: 29 Jan 2010 17:19

Re: Windows 7 "If Exist" Error.

#3 Post by BAT Beginner » 29 Jan 2010 17:50

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Windows 7 "If Exist" Error.

#4 Post by aGerman » 29 Jan 2010 17:57

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

BAT Beginner
Posts: 16
Joined: 29 Jan 2010 17:19

Re: Windows 7 "If Exist" Error.

#5 Post by BAT Beginner » 29 Jan 2010 20:54

Thank you So Much!
You are so Helpful!
~BAT Beginner

Post Reply