0

I have one file at c:\1\1.txt

In my batch program before performing any operation I have to check whether the file exists or not

My command is

If exist c:\1\1.txt Echo 1 

Its not working. In fact, because of if command the batch is crashing.

0

4 Answers 4

4

read HELP IF and then try

IF EXIST c:\1\1.txt ECHO 1 

note that you have to put the IF command, the condition, and the conditional command instruction in the same line

alternatively you can use parentheses

IF EXIST c:\1\1.txt ( ECHO 1 ) 
Sign up to request clarification or add additional context in comments.

Comments

0

It works for me. I have used this code, written in batch.bat:

@ECHO OFF If exist c:\1\1.txt ECHO 1 

Please, specify "bash is crashing".

Comments

0

test in reverse CONDITION using NOT

If NOT exist c:\1\1.txt EXIT Echo EXIST 

Comments

0

first check by command console the name of file doing

cd c:\1 dir *.txt 

why?

if you create a new file txt with notepad and save it writing in name field 1.txt, the final file name is 1.txt.txt , you can verify this with command console doing

cd c:\1 dir *.txt 

then if exist sentence work fine because 1.txt don't exist, the true name of file is 1.txt.txt.

is a posibility for this problem.

1 Comment

valid point (depends on your computer settings), but the original problem ("crashing batch") was a syntax error with the if command.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.