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-11 06:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question: how to traverse subfolders and get each subfolder name one by one View 1,005 Replies 9
Original Poster Posted 2009-02-02 11:09 ·  中国 浙江 金华 电信
新手上路
Credits 8
Posts 8
Joined 2009-01-20 10:32
17-year member
UID 137081
Gender Male
Status Offline
cd /d d:\oabak
for /f "delims=" %%d in ('dir /ad /s /b /on') do (echo %%d)
pause

I've already managed to traverse the subfolders, but how do I extract the subfolder names? HELP
Floor 2 Posted 2009-02-02 11:21 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
for /? has it

echo %%~nd
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 3 Posted 2009-02-02 11:25 ·  中国 浙江 金华 电信
新手上路
Credits 8
Posts 8
Joined 2009-01-20 10:32
17-year member
UID 137081
Gender Male
Status Offline
Thanks. Solved...
Floor 4 Posted 2009-02-02 15:45 ·  中国 浙江 金华 电信
新手上路
Credits 8
Posts 8
Joined 2009-01-20 10:32
17-year member
UID 137081
Gender Male
Status Offline
Question for everyone:
Right now I have a folder ALL, under it there are subfolders 1, 2, 3, 4, and under each of those there are many more subfolders.
Now I only want to traverse subfolders 1, 2, 3, 4, and not traverse the subfolders under 1, 2, 3, 4. How do I do that?
Floor 5 Posted 2009-02-02 15:52 ·  中国 浙江 金华 电信
新手上路
Credits 8
Posts 8
Joined 2009-01-20 10:32
17-year member
UID 137081
Gender Male
Status Offline
Question for everyone:
Right now I have a folder ALL, under it there are subfolders 1, 2, 3, 4, and under each of those there are many more subfolders.
Now I only want to traverse subfolders 1, 2, 3, 4, and not traverse the subfolders under 1, 2, 3, 4. How do I do that?
Floor 6 Posted 2009-02-02 16:25 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Floor 7 Posted 2009-02-02 16:27 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
You're in trouble now You asked here and also made another post... Duplicated.
Floor 8 Posted 2009-02-02 17:27 ·  中国 浙江 金华 电信
新手上路
Credits 8
Posts 8
Joined 2009-01-20 10:32
17-year member
UID 137081
Gender Male
Status Offline
@echo on& setlocal enabledelayedexpansion

cd /d d:\all

for /f "delims=" %%d in ('dir /ad /s /b /on %cd%') do (
set temp_subfolder=%%~nd
@ECHO !temp_subfolder!
)
PAUSE

It listed folders 1, 2, 3, 4, but the subfolders under 1, 2, 3, 4 were also listed...
Floor 9 Posted 2009-02-02 18:32 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Not sure about the situation, give this a try


@echo off
for /f "delims=" %%d in ('dir d:\all /ad /b') do (
echo %%d
set tempfolder=%%d
)
PAUSE

Floor 10 Posted 2009-02-02 18:36 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
If you add the /S parameter to dir, of course it will list all directories.

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Forum Jump: