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-12 15:11
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » What does this batch processing mean? for /f "usebackq tokens=1* View 1,611 Replies 4
Original Poster Posted 2008-08-10 11:39 ·  中国 山东 淄博 桓台县 联通
新手上路
Credits 8
Posts 2
Joined 2007-02-06 12:17
19-year member
UID 78787
Gender Male
Status Offline
for /f "usebackq tokens=1* delims=/" %%a in (`dir /b "C:\pdf\"`)

Emergency help
Floor 2 Posted 2008-08-10 11:42 ·  中国 广东 东莞 电信
初级用户
Credits 22
Posts 11
Joined 2008-07-10 21:36
18-year member
UID 121337
Gender Male
Status Offline
Extract all columns of the entire row, ignoring spaces
Floor 3 Posted 2008-08-10 13:07 ·  中国 广东 汕头 电信
高级用户
★★★
DOS时空
Credits 713
Posts 348
Joined 2007-02-10 13:59
19-year member
UID 79169
Gender Male
Status Offline
In the content output by set, use / as the delimiter, divide into two columns. Take the part to the left of the first / number as a segment to assign to %%a, and take the entire part starting from the right of the first / number as a segment to assign to %%b.

For example, the content of DIR is
c:\pdf\1.txt
c:\pdf\2.txt
c:\pdf\3.rar
c:\pdf\4.bmp

Then use \ as the delimiter,
c:
c:
c:
c:
The first column is assigned to %%a

pdf\1.txt
pdf\2.txt
pdf\3.rar
pdf\4.bmp
All are assigned to %%b

But the parameter you used here is DIR/B, which only outputs the file name, so tolens=1* delims=\ is redundant. Your sentence is standard.
Just change it to the following: for /f "delims=*" %%a in ('dir /b d:\qq\') do (
echo %%a

Combine with your above two examples and you can take a look
The following is example 1

@echo off
md d:\pdf 2>nul
type>d:\name.txt 2>nul
type>>d:\pdf\1.txt 2>nul
type>>d:\pdf\2.txt 2>nul
type>>d:\pdf\3.rar 2>nul
type>>d:\pdf\4.bmp 2>nul
for /r d:\pdf\ %%i in (*) do (
echo %%~i >>d:\name.txt
)
for /f "tokens=1* delims=\" %%a in (d:\name.txt) do (
echo %%a
)
pause



Example 2

@echo off
md d:\pdf 2>nul
type>d:\name.txt 2>nul
type>>d:\pdf\1.txt 2>nul
type>>d:\pdf\2.txt 2>nul
type>>d:\pdf\3.rar 2>nul
type>>d:\pdf\4.bmp 2>nul
for /r d:\pdf\ %%i in (*) do (
echo %%~i >>d:\name.txt
)
for /f "tokens=1* delims=\" %%a in (d:\name.txt) do (
echo %%b
)
pause


[ Last edited by haiou327 on 2008-8-10 at 01:59 PM ]
Floor 4 Posted 2008-08-10 13:09 ·  中国 广东 汕头 电信
高级用户
★★★
DOS时空
Credits 713
Posts 348
Joined 2007-02-10 13:59
19-year member
UID 79169
Gender Male
Status Offline
```
for /f "usebackq tokens=1* delims=/" %%a in (`dir /b "C:\pdf\"`) do (
echo %%a
)
```

is equivalent to

```
for /f "tokens=1* delims=/" %%a in ('dir /b C:\pdf\') do (
echo %%a
)
```

If the path has no spaces, the tokens parameter can be omitted

[ Last edited by haiou327 on 2008-8-10 at 01:57 PM ]
Floor 5 Posted 2010-03-18 16:09 ·  中国 广东 佛山 顺德区 电信
初级用户
★★
Credits 151
Posts 106
Joined 2009-10-09 21:24
16-year member
UID 152856
Gender Male
From 河南省
Status Offline
Still the enthusiasm here of ours,,, we are beginners and can't understand those two examples of yours. Can you explain them sentence by sentence? Thank you so much
Forum Jump: