• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 45
  • Last Modified:

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\"
0
stressedout2004
Asked:
stressedout2004
1 Solution
 
NVITCommented:
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
 
stressedout2004Author Commented:
This worked thank you.  It seamed to copy the files over correctly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now