DOS Batch file for searching a specific file

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
 
W

WB

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

:blush:ther_stuff

Bad programming, but the only solution for now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top