learntechnology
asked on
IF EXIST NOT WORKING for Batch file (command file) using Windows 7
I'm running the below mentioned batch file, it is copying the content without validating the access path i.e. if the accesspath for the "MSACCESS.EXE" is invalid, still it is executing the COPYCONTENT bookmark. I'm not sure IF EXIST line is correct. Please help me.
@ECHO OFF
Rem Set the path for the Office 2010 Access DB
SET AccessPath= "C:\Program Files (X86)\Microsoft Office 2010\Office14\MSACCESS.EXE"
IF EXIST AccessPath GOTO COPYCONTENT
:COPYCONTENT
Rem copy the contents file
XCOPY "c:\test\test.txt" /y "C:\Program Files\Test\" /i
Note the two changes:
Adding % around AccessPath (otherwise it is not interpreted as a variable)
Goto SkipCopy (to handle what happens when the If Exist is false
Adding % around AccessPath (otherwise it is not interpreted as a variable)
Goto SkipCopy (to handle what happens when the If Exist is false
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(Was typing that while previous comments added)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Q,
Great minds think alike...
~bp
Great minds think alike...
~bp
We three are meeting each other too often, I assume ;-).
No way, I can't get enough of you folks!
~bp
~bp
ASKER
Thanks lot for ur valuable thoughts. Let me try and keep u all posted.
I sometimes use quotes in variables, sometimes not depending upon requirements, though not too much of an issue as the os is happy to deal with quotes around different bits of filenames at the same time. Doesn't make much difference in this case but needed/better in others, agreed.
Glad to see it was of help..... why the B grade?
@ECHO OFF
Rem Set the path for the Office 2010 Access DB
SET AccessPath= "C:\Program Files (X86)\Microsoft Office 2010\Office14\MSACCESS.EXE
IF EXIST %AccessPath% GOTO COPYCONTENT
Goto SkipCopy
:COPYCONTENT
Rem copy the contents file
XCOPY "c:\test\test.txt" /y "C:\Program Files\Test\" /i
:SkipCopy