Created
August 28, 2020 19:03
-
-
Save JAffleck/ad32351fe29793d616ce7b2653f3f8f9 to your computer and use it in GitHub Desktop.
Open explorer, select file from batch file
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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