Computing.Net > Forums > Windows XP > dir /s /b for directories not subs

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

dir /s /b for directories not subs

Reply to Message Icon

Name: masimar
Date: May 11, 2006 at 18:05:51 Pacific
OS: na
CPU/Ram: na
Product: na
Comment:

Can Anybody tell be how to do a dir in windows xp and weed out the subdirectories? dir /s /b
works great, but I want only one level of directories to zip and replace the folders on the fly. The subs are just a nuiscance. I've never wanted only one level before and can't figure out how to do it. I'll do anything for help, hell, I'll #^@% your &^%$!
Well, probably not, but I would appreciate it.

Mark



Sponsored Link
Ads by Google

Response Number 1
Name: Valerie (by Garibaldi)
Date: May 11, 2006 at 19:15:26 Pacific
Reply:

Dir/ad/on/b ??


0

Response Number 2
Name: masimar
Date: May 11, 2006 at 19:33:36 Pacific
Reply:

Well, yeah. I really want the entire path that you get with dir /s /b . I can't figure how to exclude the subdirectories. That would be perfect. But I've been parsing all day and my mind wants to give up.
Thanks for the reply.

Mark


0

Response Number 3
Name: CyberSlug
Date: May 11, 2006 at 22:23:41 Pacific
Reply:

I *think* the following will work. Replace the echos with the commands you want.

@echo off

REM Recursive batch file to list files only up only to one directory deep
REM Use flag to limit recursion to one level
if "%1" == "stop" goto recursive_case

REM list files in current level
FOR /F %%i IN ('dir /b /a-D') DO echo %cd%\%%i

REM list files in subfolders
FOR /F %%i IN ('dir /b /aD') DO call %~f0 stop %cd%\%%i

:base_case
pause
exit

:recursive_case
cd %2
FOR /f "tokens=*" %%f IN ('dir /b') DO echo %cd%\%%f


0

Response Number 4
Name: masimar
Date: May 12, 2006 at 05:54:29 Pacific
Reply:

Yeah, that does the trick:
FOR /F %%i IN ('dir /b /aD') DO call %~f0 stop %cd%\%%i>>directory.txt will write just the directories in the root. Thanks a lot, that's a big help.

Mark


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: dir /s /b for directories not subs

Wildcard search for directory... not file www.computing.net/answers/windows-xp/wildcard-search-for-directory-not-file/177684.html

Choose a Directory Using Batch File www.computing.net/answers/windows-xp/choose-a-directory-using-batch-file/156129.html

Need to copy Files generated for last 1 hour www.computing.net/answers/windows-xp/need-to-copy-files-generated-for-last-1-hour/180334.html