is there a better way to write this? (batch)

Discussion in 'Scripting' started by strotee, May 14, 2022.

  1. strotee

    strotee MDL Member

    Jan 30, 2011
    229
    204
    10
    I have a batch script that I occasionally run to clean out my system. Occasionally, bleachbit gets installed into "program files" or I have it run from a portable location (c:\Apps).
    Code:
    set bleach1=C:\Apps\bleachbit\bleachbit_console.exe
    set bleach2="C:\Program Files (x86)\BleachBit\bleachbit_console.exe"
    
    if exist %bleach1% set bleach=%bleach1%
    if exist %bleach2% set bleach=%bleach2%
    %bleach% --no-uac -c -o --preset
    
     
  2. strotee

    strotee MDL Member

    Jan 30, 2011
    229
    204
    10
    #2 strotee, May 14, 2022
    Last edited: May 14, 2022
    (OP)
    I ended up writing it as follows:
    Code:
    set b_flder=bleachbit\bleachbit_console.exe
    
    if exist C:\Apps\%b_flder% (set bleach=C:\Apps\%b_flder% else (set bleach="C:\Program Files (x86)\%b_flder%")
    %bleach% --no-uac -c -o --preset
    
     
  3. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,756
    5,220
    120
    you can try .. where bleachbit_console
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. strotee

    strotee MDL Member

    Jan 30, 2011
    229
    204
    10
    could you give me an example?
     
  5. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,756
    5,220
    120
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. biorpg

    biorpg MDL Novice

    Jul 18, 2010
    33
    14
    0
    where only searches the current path and locations in the PATH variable, which doesn't include the OP's locations by default, and one can not always rely on installers to effectively add things to the PATH variable due to its default length limit.