|
chengbiner
初级用户
 
积分 105
发帖 44
注册 2006-10-5
状态 离线
|
『楼 主』:
怎样获得当前盘符并保存在文本中?
使用 LLM 解释/回答一下
比如要运行移动盘中的一个软件,但是在不同的机子上盘符会不同!
For example, to run a software on a removable disk, but the drive letter will be different on different machines!
|
|
2006-11-18 06:44 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-11-18 06:52 |
|
|
chengbiner
初级用户
 
积分 105
发帖 44
注册 2006-10-5
状态 离线
|
|
2006-11-18 06:55 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-11-18 07:07 |
|
|
chengbiner
初级用户
 
积分 105
发帖 44
注册 2006-10-5
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
谢谢斑竹,已经可以了
Thanks, moderator. It's already okay.
|
|
2006-11-18 07:09 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
关于当前盘符的获得,一般有以下三种方案:
1、cd命令:
@echo off
echo 当前路径是:%cd%
echo 当前盘符是:%cd:~0,1%
pause
2、for语句扩展:
@echo off
for %%i in (.) do set var=%%~di
echo 当前盘符是:%var:~0,1%
pause
3、参数%~0方案:
@echo off
set a=%~0
echo 当前盘符为:%a:~0,1%
pause
当然,还有其他的方案,一般都是用for语句来提取返回值特定位上的字符, 而无一例外的都需要通过截取字符的方式来实现( 蓝色部分说法不完全准确,具体情况请参考11F的举例)。
Last edited by namejm on 2006-11-24 at 08:58 PM ]
Regarding the acquisition of the current drive letter, there are generally the following three schemes:
1. cd command:
@echo off
echo Current path is: %cd%
echo Current drive letter is: %cd:~0,1%
pause
2. for statement extension:
@echo off
for %%i in (.) do set var=%%~di
echo Current drive letter is: %var:~0,1%
pause
3. Parameter %~0 scheme:
@echo off
set a=%~0
echo Current drive letter is: %a:~0,1%
pause
Of course, there are other schemes. Generally, they all use the for statement to extract the characters at the specific position of the return value, and without exception, they all need to be implemented by intercepting characters ( The statement in blue is not completely accurate. For specific situations, please refer to the example in 11F).
Last edited by namejm on 2006-11-24 at 08:58 PM ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-11-18 07:24 |
|
|
不得不爱
超级版主
         我爱DOS
积分 5310
发帖 2044
注册 2005-9-26 来自 四川南充
状态 离线
|
|
2006-11-18 07:38 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by 不得不爱 at 2006-11-17 18:38:
%~0不会得到带引号的当前路径啊
呵呵,不好意思,看走眼了,我少了个~符号。
Originally posted by Must Love at 2006-11-17 18:38:
%~0 doesn't get the quoted current path啊
Hehe, sorry, I made a mistake, I was missing a ~ symbol.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-11-18 08:07 |
|
|
hxuan999
中级用户
   DOS之日
积分 337
发帖 161
注册 2006-11-4
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
当然,还有其他的方案,一般都是用for语句来提取返回值特定位上的字符,而无一例外的都需要通过截取字符的方式来实现。
好像可以例外,不知道这样行不?
@echo off
set a=%~d0
echo 当前盘符为:%a::=%
pause
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.
It seems there can be an exception. I don't know if this works?
@echo off
set a=%~d0
echo Current drive letter is: %a::=%
pause
|

for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul |
|
2006-11-23 07:10 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
%a::=% 语句就是通过去掉显示结果中的冒号来实现的,实质上还是截取了特定位置上的字符。
The %a::=% statement is to achieve by removing the colon in the display result, essentially it is still intercepting the characters at specific positions.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-11-23 07:16 |
|
|
hxuan999
中级用户
   DOS之日
积分 337
发帖 161
注册 2006-11-4
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
受以下这个贴的启发,发现了另一个取当前盘符的方法.
请教willsort以及 各位 大哥关于prompt _$T$_
代码如下:
- @echo off
- for /f "usebackq skip=1 eol=;" %%i in (`"echo exit|%comspec% /k prompt $N$_;"`) do set "d=%%i"
- echo 当前盘符为:%d%
- pause
hxuan?表ー: 2006-11-24 15:13
还有下面这些代码,可以输出当前盘符,当前路径,当前日期,当前时间,还有版本号,当前也可以把你个性的DOS提符输出来.
- @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
hxuan?表ー: 2006-11-24 15:19
Last edited by hxuan999 on 2006-12-13 at 11:40 AM ]
Inspired by the following post, another method to get the current drive letter was discovered.
Asking willsort and all brothers about prompt _$T$_
The code is as follows:
- @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:13
There are also the following codes, which can output the current drive letter, current path, current date, current time, and version number, and can also output your personalized DOS prompt.
- @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
hxuan?表ー: 2006-11-24 15:19
Last edited by hxuan999 on 2006-12-13 at 11:40 AM ]
|

for /f %%h in (`echo hxuan`) do for /f %%x in (`echo hxuan`) do if %%h==%%x nul |
|
2006-11-25 04:11 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
prompt 属于比较冷门的命令了,却还有如此强悍的功能,值得各位重视。不错不错,给 hxuan999 加分奖励。
The `prompt` is a relatively niche command, but it has such a powerful function, which is worthy of attention from everyone. Nice nice, give hxuan999 plus points reward.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-11-25 09:54 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
欣赏~~
hxuan999兄的想像力真丰富~:)
Appreciate it~~
Brother hxuan999 has really rich imagination~ : )
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-11-25 10:20 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
prompt 属于比较冷门的命令了,却还有如此强悍的功能,值得各位重视。不错不错,给 hxuan999 加分奖励。
汗一个,想以前的DOS/9x批处理,几乎全部是 prompt 的天下,相关技巧暴多
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.
Sweat, think about the DOS/9x batch processing in the past, almost all were dominated by `prompt`, and there were tons of related skills
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-11-25 10:33 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
还可以再新开个 Prompt 的技巧讨论专贴,既能发扬技巧又能多赚积分儿~哈哈……
You can also start a new special thread for discussing Prompt techniques, which can not only carry forward the techniques but also earn more points~ Haha...
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-11-25 10:59 |
|