Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

From the current directory %CD%, I need to go inside a subfolder and execute a subrutineA, then go back to the %CD% directory and go to the next subfolder and execute the same subrutineA, this process need to be done as many time as folders available.

The problem that I have is that I dont know how to define in a batch script the name of the subdirectory since this name it´s variable, and the amount of folders it´s also variable.

Can anyone help me?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

How’s this for a start:

@echo off
for /F "delims=" %%D in ('dir/b/ad') do (
    cd "%%D"
    Do what you want to do.
    cd ..
)

share|improve this answer
    
Great, it help me a lot :D –  frantika Feb 22 '13 at 22:45

When you do not know what directory to return to and do not want to keep track of it, use pushd and popd.

@echo off
for /F "delims=" %%D in ('dir/b/ad') do (
    pushd "%%D"
    Do what you want to do.
    popd
)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.