Skip to content

Instantly share code, notes, and snippets.

@DanielAdeniji
Created July 9, 2022 18:53
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 DanielAdeniji/e7d1a1129f13fbabd22c3dab06e7fff1 to your computer and use it in GitHub Desktop.
Save DanielAdeniji/e7d1a1129f13fbabd22c3dab06e7fff1 to your computer and use it in GitHub Desktop.
DOS - Batch - Get Drive Letter
@echo off
rem Get current drive letter in CMD
rem https://stackoverflow.com/questions/21069787/get-current-drive-letter-in-cmd
setlocal
rem get contextual information
set "_contextualDrive=%cd:~0,2%"
set "_contextualFolder=%cd%"
rem get script information
set "_scriptDrive=%~d0"
set "_scriptFolder=%~p0"
set "_scriptFullPath=%~dp0"
rem display empty line
echo.
echo The Contexual Drive is %_contextualDrive%
echo The Contextual Folder Is %_contextualFolder%
rem display empty line
echo.
echo The Script Drive Is %_scriptDrive%
echo The Script Folder Is %_scriptFolder%
echo The Script Full Path Is %_scriptFullPath%
rem display empty line
echo.
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment