中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-02 16:45
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » How to read text content into a batch file
Printable Version  2,342 / 15
Floor1 ronin Posted 2006-12-06 06:02
中级用户 Posts 111 Credits 421
Floor2 a9319751 Posted 2006-12-06 06:21
中级用户 Posts 170 Credits 439
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.
Floor3 namejm Posted 2006-12-06 06:30
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Floor4 ronin Posted 2006-12-06 08:05
中级用户 Posts 111 Credits 421
Moderator namejm is right, that's exactly what I plan to do, and changing the delimiter to something else is fine too.
Floor5 namejm Posted 2006-12-06 10:25
荣誉版主 Posts 1,737 Credits 5,226 From 成都
  Then please repost a sample section of the contents of 快捷方式.txt, preferably separating the file name and file category name with a specific symbol.
Floor6 ronin Posted 2006-12-06 11:10
中级用户 Posts 111 Credits 421
Floor7 a9319751 Posted 2006-12-07 03:40
中级用户 Posts 170 Credits 439
Floor8 ronin Posted 2006-12-07 08:27
中级用户 Posts 111 Credits 421
It works, thanks.
Floor9 namejm Posted 2006-12-07 08:53
荣誉版主 Posts 1,737 Credits 5,226 From 成都
  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 ]
Floor10 a9319751 Posted 2006-12-07 09:03
中级用户 Posts 170 Credits 439
Floor11 lxmxn Posted 2006-12-07 10:09
版主 Posts 4,938 Credits 11,386

  Because delims=# , # is the delimiter, so spaces are not taken into account.
Floor12 ronin Posted 2006-12-07 11:19
中级用户 Posts 111 Credits 421
"%systemdrive%\Program Files\快捷方式.txt
If I read from a path like this, it gives an error? What's the reason?
Floor13 3742668 Posted 2006-12-07 11:37
荣誉版主 Posts 718 Credits 2,013
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?
Floor14 ronin Posted 2006-12-07 22:35
中级用户 Posts 111 Credits 421
When I use ", the program reports an error and the function can't be implemented. Not using " means the path is wrong.
Floor15 namejm Posted 2006-12-07 22:52
荣誉版主 Posts 1,737 Credits 5,226 From 成都
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023