Last active
August 29, 2015 14:20
-
-
Save maphew/0cdd85e44691429ac33b to your computer and use it in GitHub Desktop.
A pattern I find myself repeating a lot: "Test if program is in path, attempt to extend path, list available commands in .\bin." The example here is for LAS Tools, but really it could be anything.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Test if Lastools are in path, if not extend path and try again. | |
:: we assume desired tool folder is ".\bin" relative to the batch file | |
lasinfo -i >nul 2>&1 | |
if %errorlevel%==9009 set path=%~dp0\bin;%path% | |
lasinfo -i >nul 2>&1 | |
if not "%errorlevel%"=="1" goto :NoTools | |
call :ShowCommands | |
:: Allows starting shell from Windows Explorer | |
:: can be removed if you never do that. | |
cmd | |
goto :eof | |
:: -------------------------------------------------------------------- | |
:NoTools | |
echo. | |
echo. *** Didn't find LASTools in "%~dp0\bin" | |
echo. | |
goto :eof | |
:ShowCommands | |
:: Generate list of executables in the .\bin folder and report nicely to user | |
echo. -={ LAS Tools Commands }=- | |
setlocal EnableDelayedExpansion | |
rem Generate executables list | |
pushd "%~dp0\bin" | |
for %%a in (exe com bat) do ( | |
echo. >> "%temp%\o-help-list.txt" | |
if exist *.%%a dir /d *.%%a |find ".%%a" >>"%temp%\o-help-list.txt" | |
) | |
popd | |
rem Strip extensions and report just names | |
rem c.f. http://ss64.com/nt/syntax-replace.html | |
for /f "usebackq delims=?" %%g in ("%temp%\o-help-list.txt") do ( | |
set _s=%%g | |
set _s=!_s:.exe=! | |
set _s=!_s:.com=! | |
set _s=!_s:.bat=! | |
echo. !_s! | |
) | |
echo. | |
del "%temp%\o-help-list.txt" | |
goto :eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is what it looks like when run: