Batch File Copy Check If Directory Exists Before Copying

I need a batch file that checks if a directory exists and if it does to copy the file.  I cant get this to work

If Exist "C:\Program Files (x86)\Mozilla Firefox\browser\extensions\" goto EXISTSxpi
:EXISTSxpi copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\plugin@okta.com.xpi" "C:\Program Files (x86)\Mozilla Firefox\browser\extensions\"


If Exist "C:\Program Files (x86)\Mozilla Firefox\" goto EXISTScfg
:EXISTScfg copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-mozilla.cfg" "C:\Program Files (x86)\Mozilla Firefox\"


If Exist "C:\Program Files (x86)\Mozilla Firefox\defaults\pref\" goto :EXISTSjs
:EXISTSjs copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-prefs.js" "C:\Program Files (x86)\Mozilla Firefox\defaults\pref\"


If Exist "C:\Program Files\Mozilla Firefox\browser\extensions\" goto EXISTS64xpi
:EXISTS64xpi copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\plugin@okta.com.xpi" "C:\Program Files\Mozilla Firefox\browser\extensions\"


If Exist "C:\Program Files\Mozilla Firefox\" goto EXISTS64cfg
:EXISTS64cfg copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-mozilla.cfg" "C:\Program Files\Mozilla Firefox\"


If Exist "C:\Program Files\Mozilla Firefox\" goto EXISTS64js
:goto EXISTS64js copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-prefs.js" "C:\Program Files\Mozilla Firefox\defaults\pref\"
LVL 9
stressedout2004Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
Please post your code using the Code formatting icon.

2. In your original, the COPY lines should be on their own lines, i.e.:
If Exist "C:\Program Files (x86)\Mozilla Firefox\browser\extensions\" goto EXISTSxpi
:EXISTSxpi
copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\plugin@okta.com.xpi" "C:\Program Files (x86)\Mozilla Firefox\browser\extensions\"


If Exist "C:\Program Files (x86)\Mozilla Firefox\" goto EXISTScfg
:EXISTScfg
copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-mozilla.cfg" "C:\Program Files (x86)\Mozilla Firefox\"


If Exist "C:\Program Files (x86)\Mozilla Firefox\defaults\pref\" goto :EXISTSjs
:EXISTSjs
copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-prefs.js" "C:\Program Files (x86)\Mozilla Firefox\defaults\pref\"


If Exist "C:\Program Files\Mozilla Firefox\browser\extensions\" goto EXISTS64xpi
:EXISTS64xpi
copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\plugin@okta.com.xpi" "C:\Program Files\Mozilla Firefox\browser\extensions\"


If Exist "C:\Program Files\Mozilla Firefox\" goto EXISTS64cfg
:EXISTS64cfg
copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-mozilla.cfg" "C:\Program Files\Mozilla Firefox\"


If Exist "C:\Program Files\Mozilla Firefox\" goto EXISTS64js
:goto EXISTS64js
copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\okta-prefs.js" "C:\Program Files\Mozilla Firefox\defaults\pref\"

Open in new window


Even with that, it will still goto the next line because you have no ELSE condition or alternative statement. Maybe you need something like and :EOF
If Exist "C:\Program Files (x86)\Mozilla Firefox\browser\extensions\" goto EXISTSxpi
goto :EOF
:EXISTSxpi
copy /y "\\vir-storage\common\SHARED\IT Department\OktaBrowserPlugins\plugin@okta.com.xpi" "C:\Program Files (x86)\Mozilla Firefox\browser\extensions\"
...

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stressedout2004Author Commented:
This worked thank you.  It seamed to copy the files over correctly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.