中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-09 10:30
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » for /f 命令里,delims若指定为",如何来实现 查看 804 回复 5
楼 主 for /f 命令里,delims若指定为",如何来实现 发表于 2008-08-04 00:59 ·  中国 湖北 荆门 电信
新手上路
积分 6
发帖 2
注册 2008-08-04 00:30
18年会员
UID 122752
性别 男
状态 离线
RT
s.txt 内容如下:
i"love"u


用for /f 命令来读取love:
@echo off
for /f "tokens=2 delims="" %%i in (s.txt) do echo %%i


这里的"貌似有问题 执行出错

请各位大大教教小菜 若要将delims指定为" 时,如何实现?

PS.在一个帖子里看到一行命令:
if /i "%~d0"=="c:" (exit) else (cd c:)


这里的%~d0是什么意思?指的是什么?

感谢各位大大不吝赐教

[ Last edited by Will on 2008-8-4 at 01:09 AM ]
2 发表于 2008-08-04 01:50 ·  中国 山东 淄博 联通
银牌会员
★★★
积分 1,604
发帖 646
注册 2008-04-13 23:39
18年会员
UID 115804
性别 男
状态 离线
@echo off
set/p var=<s.txt
for /f "tokens=2" %%a in ("%var:"= %") do echo %%a
pause>nul


%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file
%~$PATH:1 - searches the directories listed in the PATH
environment variable and expands %1 to the fully
qualified name of the first one found. If the
environment variable name is not defined or the
file is not found by the search, then this
modifier expands to the empty string

[ Last edited by pusofalse on 2008-8-4 at 01:51 AM ]
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
3 发表于 2008-08-04 07:12 ·  中国 四川 成都 电信
中级用户
★★
积分 297
发帖 135
注册 2006-10-21 12:00
19年会员
UID 67627
性别 男
状态 离线
各位前辈早已得出的结论是:双引号"不能做为delims的分隔符!

没想到现在还有人不信这个邪!(当然也可能是前辈们没有找到而已)
4 发表于 2008-08-04 10:20 ·  美国 惠普HP
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
@echo off
set str=i"love"u
set str=%str:"=#%
for /f "tokens=2 delims=#" %%i in ("%str%") do echo %%i
5 发表于 2008-08-06 04:24 ·  中国 广东 广州 电信
银牌会员
★★★
积分 1,206
发帖 517
注册 2007-03-25 01:18
19年会员
UID 82819
性别 男
状态 离线
Originally posted by zqz0012005 at 2008-8-4 07:12 AM:
各位前辈早已得出的结论是:双引号"不能做为delims的分隔符!

没想到现在还有人不信这个邪!(当然也可能是前辈们没有找到而已)



嗯。是啊。是不能做为delims的分隔符。
但并不代表不可以用 “ 分隔。。。
知,不觉多。不知,乃求知
6 发表于 2008-08-19 16:24 ·  中国 湖北 荆门 电信
新手上路
积分 6
发帖 2
注册 2008-08-04 00:30
18年会员
UID 122752
性别 男
状态 离线
感谢各位大大 原来是把"用其他的字符替换…
论坛跳转: