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-09 10:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How do I read the contents of a long filename? View 889 Replies 6
Original Poster Posted 2008-07-31 04:41 ·  中国 云南 昆明 电信
中级用户
★★
Credits 220
Posts 99
Joined 2008-06-26 15:12
18-year member
UID 120818
Gender Male
Status Offline
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...```
Floor 2 Posted 2008-07-31 07:43 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
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 ]
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 3 Posted 2008-07-31 10:18 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
@echo off
set t=0
for /F "usebackq eol== tokens=1 delims= " %%a in ("2008-07-31 星期四.txt") do (
set /a t+=%%a
)
echo %t%
Floor 4 Posted 2008-07-31 16:21 ·  中国 云南 昆明 电信
中级用户
★★
Credits 220
Posts 99
Joined 2008-06-26 15:12
18-year member
UID 120818
Gender Male
Status Offline
Originally posted by HAT at 2008-7-31 10:18 AM:
@echo off
set t=0
for /F "usebackq eol== tokens=1 delims= " %%a in ("2008-07-31 星期四.txt") do (
set /a t+=%%a
)
echo %t%


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
Floor 5 Posted 2008-07-31 17:31 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
The code in reply #4 doesn't work, right?
If you want to use type, at least use single quotes :)
Floor 6 Posted 2008-08-01 04:27 ·  中国 云南 昆明 电信
中级用户
★★
Credits 220
Posts 99
Joined 2008-06-26 15:12
18-year member
UID 120818
Gender Male
Status Offline
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
Floor 7 Posted 2008-08-01 04:28 ·  中国 云南 昆明 电信
中级用户
★★
Credits 220
Posts 99
Joined 2008-06-26 15:12
18-year member
UID 120818
Gender Male
Status Offline
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
Forum Jump: