DOS Batch file for searching a specific file

  • Thread starter Thread starter Pr_ngp
  • Start date Start date
P

Pr_ngp

Below is the dos script which I have write to search files in specific folder:

@echo off
c:

if exist c:\Data\*.txt (echo FILE_EXIST) else (echo FILE DOES NOT EXIST)
PAUSE

Now I am getting message FILE DOES NOT EXIST all the time even if the file
is there.

if i change
if exist c:\Data\*.* (echo FILE_EXIST) else (echo FILE DOES NOT EXIST)

i*.* instead of *.txt then I get FILE_EXIST message all the time even if the
file is not there.

I am not getting correct message. Any help?
Thanks in advance.
Edit/Delete Message
 
I've noticed that if I use a lot of logic in a batch file with a lot of
parenthesis, things get screwed up. This is a bug with the Microsoft batch
language that they will never fix. The only solution I've found is to use
labels and avoid parens whenever possible:

if not exist c:\Data\*.txt goto error
echo FILE_EXIST
goto other_stuff

:error
echo FILE DOES NOT EXIST
PAUSE

:other_stuff

Bad programming, but the only solution for now.
 
Back
Top