Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm having trouble creating a .bat file to do the following;

IF OS xp
run xcopy

IF OS Win 7 
run xcopy

Else
exit

To keep it simple I would like to the use IF EXIST "C:\Program Files (x86)\." THEN windows 7

Can anyone please help?

share|improve this question
    
stackoverflow.com/questions/13212033/…. use the output to branch accordingly. –  Robert Kerr May 9 '13 at 9:08
    
Please edit your question to include the batch you've got so far. –  CharlieRB May 9 '13 at 12:29
add comment

1 Answer

Try this:

@echo off
setlocal EnableDelayedExpansion

for /F "delims=" %%a in ('ver') do set ver=%%a
set Version=
for %%a in (95=95 98=98 ME=ME NT=NT 2000=2000 5.1.=XP 5.2.=2003 6.0.=Vista 6.1.=7 6.2.=8) do (
   if "!Version!" equ "this" (
      set "Version=%%a"
   ) else if "!ver: %%a=!" neq "%ver%" (
      set Version=this
   )
)
goto:_%version% 2>nul || goto:eof

:_xp
:_7
xcopy /?

© Aacini at dostips

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.