中国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-09 09:12
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » How do I read the contents of a long filename?
Printable Version  887 / 6
Floor1 23112656 Posted 2008-07-31 04:41
中级用户 Posts 99 Credits 220
The basic idea is this:
I created test.txt and a txt file created with %date% in a directory, that is, in a format like this: 2008-07-31 Thursday.txt, but the problem is here: why can the code below only read the contents of test.txt, but not a long filename with spaces like "2008-07-31 Thursday.txt"?
set t=0
for /F "eol== tokens=1 delims= " %%a in (the problematic part) do (
set /A t+=%%a
)
echo %t%

What I originally wanted was to add up the numbers in the first column of the text file. If I change the problematic part to test.txt there's no problem, but if I change it to the text file in that date format, it doesn't work. Experts, please give me a hand...```
Floor2 pusofalse Posted 2008-07-31 07:43
银牌会员 Posts 646 Credits 1,604
2008-07-31 星期四.txt has spaces, so you need to enclose it with "", and also add usebackq to the for options, before eol==

[ Last edited by pusofalse on 2008-7-31 at 07:45 AM ]
Floor3 HAT Posted 2008-07-31 10:18
版主 Posts 5,017 Credits 9,023
Floor4 23112656 Posted 2008-07-31 16:21
中级用户 Posts 99 Credits 220
Originally posted by HAT at 2008-7-31 10:18 AM:


Thanks so much` but I found that changing it to
for /F "usebackq eol== tokens=1 delims= " %%a in (type "%date% ???.txt") do (
set /a t+=%%a
)
echo %t%

also works` thanks
Floor5 HAT Posted 2008-07-31 17:31
版主 Posts 5,017 Credits 9,023
The code in reply #4 doesn't work, right?
If you want to use type, at least use single quotes :)
Floor6 23112656 Posted 2008-08-01 04:27
中级用户 Posts 99 Credits 220
Originally posted by HAT at 2008-7-31 05:31 PM:
The code in reply #4 doesn't work, right?
If you want to use type, at least use single quotes :)


Hehe``` I forgot to write that part` that's the general idea
Floor7 23112656 Posted 2008-08-01 04:28
中级用户 Posts 99 Credits 220
Originally posted by HAT at 2008-7-31 05:31 PM:
The code in post #4 doesn't work, right?
If you want to use type, at least use single quotes :)


Hehe``` I forgot to write that part` that's the general idea
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023