For example, to run a software on a removable disk, but the drive letter will be different on different machines!
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
@echo off
echo Current path is: %cd%
echo Current drive letter is: %cd:~0,1%
pause
@echo off
for %%i in (.) do set var=%%~di
echo Current drive letter is: %var:~0,1%
pause
@echo off
set a=%~0
echo Current drive letter is: %a:~0,1%
pause
| Rater | Score | Time |
|---|---|---|
| redtek | +3 | 2006-11-26 00:02 |
Originally posted by Must Love at 2006-11-17 18:38:
%~0 doesn't get the quoted current path啊
Of course, there are other solutions. Generally, for statements are used to extract characters at specific positions in the return value, and without exception, they all need to be implemented by intercepting characters.
@echo off
set a=%~d0
echo Current drive letter is: %a::=%
pause
hxuan?表ー: 2006-11-24 15:13
- @echo off
- for /f "usebackq skip=1 eol=;" %%i in (`"echo exit|%comspec% /k prompt $N$_;"`) do set "d=%%i"
- echo The current drive letter is: %d%
- pause
hxuan?表ー: 2006-11-24 15:19
- @echo off
- for /f "usebackq skip=1 eol=; delims=" %%i in (`"echo exit|%comspec% /k prompt $N$_;"`) do set "aaa=%%i"
- echo %aaa%
- for /f "usebackq skip=1 eol=; delims=" %%i in (`"echo exit|%comspec% /k prompt $D$_;"`) do set "aaa=%%i"
- echo %aaa%
- for /f "usebackq skip=1 eol=; delims=" %%i in (`"echo exit|%comspec% /k prompt $E$_;"`) do set "aaa=%%i"
- echo %aaa%
- for /f "usebackq skip=1 eol=; delims=" %%i in (`"echo exit|%comspec% /k prompt $P$_;"`) do set "aaa=%%i"
- echo %aaa%
- for /f "usebackq skip=1 eol=; delims=" %%i in (`"echo exit|%comspec% /k prompt $T$_;"`) do set "aaa=%%i"
- echo %aaa%
- for /f "usebackq skip=1 eol=; delims=" %%i in (`"echo exit|%comspec% /k prompt $V$_;"`) do set "aaa=%%i"
- echo %aaa%
- pause
| Rater | Score | Time |
|---|---|---|
| namejm | +2 | 2006-11-25 09:55 |
The `prompt` command is relatively niche, yet it has such powerful functions, which is worthy of everyone's attention. Not bad, give hxuan999 a bonus.