Link to home
Start Free TrialLog in
Avatar of Tammu
Tammu

asked on

if exist command in a batch flle

Hello Experts,

i have a simple batch file to check if a file exist in a particular directory, if so then copy it to some other directory and then display a message saying file copied. if the file does not exist in that directory look for the file in another directory and do same process again.

my batch file works properly, the only problem is it displays file copied message whether the file exist or not.

basically if the file in the first IF does not exist then i dont want the file copied message from the first if condition be displayed.

hope i am clear in explaining.

Thanks appreicate it

@echo off
IF EXIST c:\Test1\batchMsgBoxFile.bat copy c:\Test1\batchMsgBoxFile.bat c:\DisplayBatch\batchMsgBoxFile.txt
echo x=msgbox("file copied") > message1.vbs
start message1.vbs
IF NOT EXIST GOTO TEST2FILE

:TEST2FILE

copy c:\Test2\batchMsgBoxFile.bat c:\DisplayBatch\batchMsgBoxFile.bat
call c:\DisplayBatch\batchMsgBoxFile.bat
echo x=msgbox("file copied to Test2 folder") > message2.vbs
start message2.vbs

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
However, there are more simple means to display a message box, like the msg command:

msg * "File 1 copied" /time:5
will display a message box for 5 seconds, while continueing to proceed with the batch file.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

A couple of other thoughts on message boxes from BAT files.

http://claudiosoft.online.fr/msgbox.html

http://www.robvanderwoude.com/usermessages.php

~bp
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tammu

ASKER

Thanks to everyone. all the suggested methods helped and hence i gave point equally to everyone. appreciate it

Avatar of Tammu

ASKER

Thanks