Management of directories and subrutines

0

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?

frantika

Posted 2013-02-22T18:46:18.373

Reputation: 25

Answers

0

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 ..
)

Scott

Posted 2013-02-22T18:46:18.373

Reputation: 17 653

Great, it help me a lot :D – frantika – 2013-02-22T22:45:53.143

1

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
)

David Ruhmann

Posted 2013-02-22T18:46:18.373

Reputation: 1 199