0

Last time I used batch files, I learned with examples from an MSDOS 5.0 book. Now, while trying to apply a command on all files in a directory, I stumbled upon

for %%J in (*.exe *.dll) do @echo %%J 

I thought "this can't be a batch file", but yet it works.

Q1: How is this new format called and/or where do I find a list of things I can do with this new format?

Q2: (*.exe *.dll) is not a DOS-style command; so what is it?

Q3: How do I modify this "command" to include files in all subdirectories?

1
  • The command you listed works in MSDOS V5 too, without the @ Commented Dec 11, 2013 at 9:07

2 Answers 2

1
  1. Informally, NT batch. Oficially, who cares?

  2. Certainly is dos-style. * has always meant matches anything Perhaps not in a FOR command, but that's NT batch for you. Enhancements, see?

  3. Look at

    FOR /?

from the prompt.

Or generally

commandname /?

Or go to Help & Support and look for command line

Sign up to request clarification or add additional context in comments.

Comments

0

It is a DOS style command. The format of for-loop in DOS:

FOR %variable IN (set) DO command [command-parameters]

(*.exe *.dll) is the set in the for command, it means all files with exe and dll extensions.
* is the wildcard character.

So this command will echo the names of all exe and dll files in the current directory.

You can use following for-loop to include files in all subdirectories:

@echo off for /F "delims==" %%d in ('dir /s /b /o:gn *.exe *.dll') DO ( ECHO %%d ) 

1 Comment

Excuse me. This is NOT Delayed Expansion. Your program will work removing setlocal enabledelayedexpansion command and there is not a single variable enclosed in exclamation marks here! Please, don't confuse the beginner even more...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.