Kelly
Kelly

Reputation: 213

Skipping specific directory using for loop in a Batch script

I am trying to process all the directory present in a given directory. However, i want to skip a particular set of directories and i know the names of these directory. Here's the pseudo code

for /D %%G in ("%ROOT_VAR%\mainDirectory\*") do (
if "%%G" == "%%ROOT_VAR%%\mainDirectory\dir_to_be_skipped" (
echo "Skipping dir_to_be_skipped"
)

continue processing other directory

How do i do that in batch script ? I just want to skip processing dir_to_be_skipped

Thank Kelly

Upvotes: 0

Views: 323

Answers (1)

Blorgbeard
Blorgbeard

Reputation: 103447

Easy! Add an else:

for /D %%G in ("%ROOT_VAR%\mainDirectory\*") do (
    if "%%G" == "%%ROOT_VAR%%\mainDirectory\dir_to_be_skipped" (
        echo "Skipping dir_to_be_skipped"
    ) else (
        continue processing other directory
    )
)

Note that the ) else ( must all be on the same line.

Upvotes: 1

Related Questions