Search code examples
batch-filedosbatch-processingxcopy

Execute Set of Batch Commands on Condition TRUE


I have a .bat file with certain commands which it executes (XCOPY/DEL/RMDIR,etc)

Now what I want is, initially show a prompt to the user, as soon as the .bat is RUN. Only IF the user says Y to the prompt should the complete set of commands should be executed. ELSE it should just EXIT. How do I do this?


Solution

  • set answer=N
    set /P answer=Do you want to proceed? 
    if /I not %answer% == Y exit /B
    rem Continue here...
    

    First SET command set a default value if the user just press Enter. The /I switch in IF command ignore case in comparison.