Results 1 to 4 of 4

Thread: Batch Case Statement

  1. #1
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default Batch Case Statement

    Okay, so this is what I have so far... My concern is if there is a way to shorten this. I would rather it just detect if x directory exists it replaces it - if more than x directories exists returns an error. Currently it'll go through all of them - and if multiple locations exists it'll replace the addin in both locations.
    Simba Code:
    @ECHO OFF
    :CASE_O12
    xcopy /y "C:\Source" "C:\Program Files (x86)\Microsoft Office\Office12\Library"
    GOTO END_CASE

    :CASE_O14
    xcopy /y "C:\Source" "C:\Program Files (x86)\Microsoft Office\Office14\Library"
    pause

    :CASE_O15
    xcopy /y "C:\Source" "C:\Program Files (x86)\Microsoft Office\Office15\Library"
    GOTO END_CASE

    :END_CASE
    ECHO Successfully replaced addin!
    pause

    Title Replace Addin
    ECHO.
    ECHO Replacing Addin
    IF EXIST "C:\Program Files (x86)\Microsoft Office\Office12\Library" GOTO CASE_012
    IF EXIST "C:\Program Files (x86)\Microsoft Office\Office14\Library" GOTO CASE_014
    IF EXIST "C:\Program Files (x86)\Microsoft Office\Office15\Library" GOTO CASE_015

    Edit: Also if anyone could give me some insight on how to make this into an executable program with a GUI that'd be awesome.
    Last edited by Clutch; 06-26-2015 at 09:41 PM.

  2. #2
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    This is a rewrite of the initial code you posted;
    Code:
    @echo off
    set "destDir=C:\Source"
    call :checkExists "C:\Program Files (x86)\Microsoft Office\Office12\Library" "%destDir%"
    call :checkExists "C:\Program Files (x86)\Microsoft Office\Office14\Library" "%destDir%"
    call :checkExists "C:\Program Files (x86)\Microsoft Office\Office15\Library" "%destDir%"
    EXIT /B
    :checkExists
    if exist "%1" (
    	xcopy %1 %2
    )
    goto:EOF
    Adding this to an executable program with a GUI would be much more work that this simple program is worth in my opinion.

    However if it's really important, you could simply make a java swing GUI, then wrap the executable with Launch4j.

    Your post lacks many details and contents as how to proceed with a more in-depth approach.
    Questions I would ask include:
    1. What layout would the GUI be?
    2. What would go on the GUI (what functionality/components/etc)?
    3. Is this windows dependent? (could make into cross-platform)
    4. Is this a simple script, or are you trying to use this on a large scale basis (lots and lots of files being used)
    5. etc.

    -lj

  3. #3
    Join Date
    Jan 2012
    Posts
    190
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default

    Well there arent any really CASE implementation in Batch really at all but you are probablly looking for a directory walker...
    and if directory exists

    Code:
    @echo off
    for /r "C:\Program Files (x86)\Microsoft Office" %%a in (.) do echo %%~fa
    pause
    
    this will list folder tree...
    if you know the name of the folder
    
    @echo OFF
    setlocal enabledelayedexpansion
    for /r "C:\Program Files (x86)\Microsoft Office" %%a in (.) do (
    IF "%%~fa" == "C:\Program Files (x86)\Microsoft Office\Office12\Library" (
    MKDIR "C:\FOLDER" 
    XCOPY "C:\Program Files (x86)\Microsoft Office\Office12\Library" "C:\FOLDER" ) 
    )
    pause

  4. #4
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    This is a rewrite of the initial code you posted;
    Code:
    @echo off
    set "destDir=C:\Source"
    call :checkExists "C:\Program Files (x86)\Microsoft Office\Office12\Library" "%destDir%"
    call :checkExists "C:\Program Files (x86)\Microsoft Office\Office14\Library" "%destDir%"
    call :checkExists "C:\Program Files (x86)\Microsoft Office\Office15\Library" "%destDir%"
    EXIT /B
    :checkExists
    if exist "%1" (
    	xcopy %1 %2
    )
    goto:EOF
    Adding this to an executable program with a GUI would be much more work that this simple program is worth in my opinion.

    However if it's really important, you could simply make a java swing GUI, then wrap the executable with Launch4j.

    Your post lacks many details and contents as how to proceed with a more in-depth approach.
    Questions I would ask include:
    1. What layout would the GUI be?
    2. What would go on the GUI (what functionality/components/etc)?
    3. Is this windows dependent? (could make into cross-platform)
    4. Is this a simple script, or are you trying to use this on a large scale basis (lots and lots of files being used)
    5. etc.

    -lj
    Thanks, I'll look over this later when I get time!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •