Batch program to listi sub-folder

Microsoft Xbox 360 premium system
December 6, 2009 at 20:06:32
Specs: Windows XP
I need a batch program to list the subfolders from two directories only. Ex. c:\test\abc and c:\test1\abcd i want to list all the immediate subfolders from above directories. Can any one help me out.

See More: Batch program to listi sub-folder

Report •


#1
December 7, 2009 at 00:39:32
<Untested>

set var=c:\test\abc
for /d %%a ("%var:"=%\*") do echo %%a


Batch Variable how to


Report •

#2
December 7, 2009 at 02:06:20
Thanks for the response.
Above code could not solve my problem. I need to list sub-directories from two different directories i.e i need to use something like "AND" condition in for loop to display.How could i use the two different directories i.e c:\test\abc and c:\program\abc in the single for loop to display their subdirectories?

Report •

#3
December 7, 2009 at 02:15:16
Easy the for loop can contain a set(i.e. both folders), but
there will be no warning when the first finishes and the
second begins. I used a variable above because it's not
so common to have hard coded folders.

for /d %%a in ("c:\test\abc\*" "c:\program\abc\*") do echo %%a


Batch Variable how to


Report •

Related Solutions

#4
December 7, 2009 at 19:15:45
Thanks, it solved my problem.

Report •

#5
December 7, 2009 at 20:15:43
oh, there is still some problem.Following is the code i worked out:
To display the subdirectories in two different directories with number like 1,2,3 ..

set /A Counter=1
if exist "c:\test\abc" (
FOR /f "tokens=*" %%G IN (' dir/b c:\test\abc\*.*') do (
echo !Counter!. %%G "c:\test\abc"
set /A Counter+=1
)
)

if exist "c:\test1" (
FOR /f "tokens=*" %%G IN (' dir/b c:\test1\*.*') do (
echo !Counter!. %%G "c:\test1"
set /A Counter+=1
)
)

echo %Counter%. Other (manually type the path )
echo.

I prompt user to enter the number i.e related with counter value displayed .
set /p usrin=Which number do you want to use?

Now i need a batch script such that
if user input is the last number(i.e counter value) echo "last number" and associated directory name
if user input is 1 to before last number echo "number" and and associated directory name .

Your help is highly appreciated.


Report •

#6
December 7, 2009 at 20:55:20
You can fill in the blanks. One thing to note though,
the selection won't be valid if the contents of the
directory change from when there listed to when there
selected, if this is a problem then a list of variables
can be used instead. I also added all important input
validation:

@ECHO OFF
setlocal enabledelayedexpansion
set counter=
FOR /f "tokens=*" %%G IN (' dir/b ') do (
    set /A Counter+=1
    echo !Counter!. %%G
)


:select
set /p usrin=Which number do you want to use, 0 exits?
if defined usrin (
    set test=!usrin!
    for /l %%a in (1 1 9) do if defined test set test=!test:%%a=!
    if not defined test (
        if !usrin! leq !counter! (
            goto valid
        )
    )        
)
if "!usrin!"=="0" exit /b
echo Bad input.
goto select

:valid
FOR /f "skip=%usrin% tokens=*" %%G IN (' echo d ^& dir/b') do (
    if %counter% equ %usrin% (
        echo blah blah %%G
    ) else (
        echo blah %%G
    )
    goto break

)

:break
pause


Batch Variable how to


Report •


Ask Question