Outline
Current Folder
Symbol | Meaning | Explanation |
---|---|---|
%cd% | Change Directory/Current Directory | |
%cd:~0,2% | Change Directory/Current Directory | 1) cd means to get current folder
2) :~0,2 2a) 0 means do not skip any characters 2b) 2 means to get the next two characters |
Running Script
Symbol | Meaning |
---|---|
%~d0 | Running Script Full Drive |
%~p0 | Running Script Folder |
%~dp0 | Running Script Full Path Name |
Script
@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
Crediting
As always, who you gonna call….
- Get Current Drive Letter
https://stackoverflow.com/questions/21069787/get-current-drive-letter-in-cmd
Link
When Not available
- Ray Parker Jnr.
- MacGyver
- Cops – Bab Boys, Bad Boys, Shut/Shot on location.
Try StackOverflow.
Code Sharing
Referenced Material
- SS64
- How-to: Extract part of a variable (substring)
Link
- How-to: Extract part of a variable (substring)