Skip to content

Instantly share code, notes, and snippets.

@JAffleck
Created August 28, 2020 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JAffleck/ad32351fe29793d616ce7b2653f3f8f9 to your computer and use it in GitHub Desktop.
Save JAffleck/ad32351fe29793d616ce7b2653f3f8f9 to your computer and use it in GitHub Desktop.
Open explorer, select file from batch file
@echo off
set filename=%1
set "strToMeasure=%CD%"
call :strLen strToMeasure strlen
@REM echo.String is %strlen% characters long
call :filePath %strlen% %filename%
exit /b
@REM methods stolen to get string length
@REM https://stackoverflow.com/a/17352941
:strLen
setlocal enabledelayedexpansion
:strLen_Loop
if not "!%1:~%len%!"=="" set /A len+=1 & goto :strLen_Loop
(endlocal & set %2=%len%)
goto :eof
:filePath
if("%1"==3) (set FILEPATH="%CD%%filename%") else (set FILEPATH="%CD%\%filename%")
echo.FILEPATH=%FILEPATH%
explorer.exe /select, %FILEPATH%
explorer.exe /select, %FILEPATH%
goto :eof
@JAffleck
Copy link
Author

I have this file in a folder added to path (environment variable), then to use it just do
select.bat filename
(Note you must be 'cd'd in the folder with the filename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment