where /R "C:\Program Files\CodeBlocks" gcc.exe > tmpFile SET /p CSPATH= < tmpFile DEL tmpFile if defined CSPATH ( echo file1:"%CSPATH:~0,-8%" ) else ( where /R "C:\Program Files (x86)\CodeBlocks" gcc.exe > tmpFile SET /p CSPATH= < tmpFile DEL tmpFile if defined CSPATH ( echo file2:"%CSPATH:~0,-8%" ) else ( where /R "C:\\" gcc.exe > tmpFile SET /p CSPATH= < tmpFile DEL tmpFile if defined CSPATH ( echo file2:"%CSPATH:~0,-8%" ) else ( echo File not found ) ) ) if defined CSPATH ( for %%p in (gcc.exe) do set "progpath=%%~$PATH:p" if not defined progpath ( C:\Windows\System32\setx.exe PATH "%CSPATH:~0,-8%;%PATH%" /M ) )