China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

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!

中国DOS联盟论坛
The time now is 2026-08-02 17:59
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to read text content into a batch file View 2,347 Replies 15
Original Poster Posted 2006-12-06 06:02 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
Floor 2 Posted 2006-12-06 06:21 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
for /f "tokens=1,2 skip=1 delims=;" %%i in (1.txt) do @echo %%i+%%j
pause

In your text, the first quote mark is the Chinese “ and the second is the English ", I suggest removing the Chinese “, and it's best to change the English " to some other delimiter so CMD can recognize it.
bat c c++
Floor 3 Posted 2006-12-06 06:30 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 4 Posted 2006-12-06 08:05 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
Moderator namejm is right, that's exactly what I plan to do, and changing the delimiter to something else is fine too.
Floor 5 Posted 2006-12-06 10:25 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
  Then please repost a sample section of the contents of 快捷方式.txt, preferably separating the file name and file category name with a specific symbol.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 6 Posted 2006-12-06 11:10 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
Floor 7 Posted 2006-12-07 03:40 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
ronin +4 2006-12-07 08:28
bat c c++
Floor 8 Posted 2006-12-07 08:27 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
It works, thanks.
Floor 9 Posted 2006-12-07 08:53 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
  One more thing: if the filename has spaces, then tokens has to be changed to tokens=1*.

───────────────────────────────────────────────────────────
  Without testing it first, I was influenced by habitual thinking, which made the above statement incorrect. Please see the test in post #10 and the analysis in post #11 below.

[ Last edited by namejm on 2006-12-6 at 09:21 PM ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 10 Posted 2006-12-07 09:03 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
bat c c++
Floor 11 Posted 2006-12-07 10:09 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  Because delims=# , # is the delimiter, so spaces are not taken into account.
Floor 12 Posted 2006-12-07 11:19 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
"%systemdrive%\Program Files\快捷方式.txt
If I read from a path like this, it gives an error? What's the reason?
Floor 13 Posted 2006-12-07 11:37 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Originally posted by ronin at 2006-12-7 11:19:
"%systemdrive%\Program Files\快捷方式.txt
If I read from a path like this, it gives an error? What's the reason?

"%systemdrive%\Program Files\快捷方式.txt"
Are the quotation marks being used correctly?
Floor 14 Posted 2006-12-07 22:35 ·  中国 广东 梅州 电信
中级用户
★★
Credits 421
Posts 111
Joined 2003-08-29 00:00
22-year member
UID 9153
Gender Male
Status Offline
When I use ", the program reports an error and the function can't be implemented. Not using " means the path is wrong.
Floor 15 Posted 2006-12-07 22:52 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Forum Jump: