Alexander
Alexander

Reputation: 20224

New batch file format / commands?

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?

Upvotes: 0

Views: 99

Answers (2)

Infinite Recursion
Infinite Recursion

Reputation: 6557

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
)

Upvotes: 0

Magoo
Magoo

Reputation: 79982

  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

Upvotes: 1

Related Questions