Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

IF OS xp
run xcopy

IF OS Win 7 
run xcopy


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…. 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

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

xcopy /?

© Aacini at dostips

share|improve this answer

Your Answer


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.