Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My folder structure in a drive is like this (in Windows):

Folder 1
Folder 2

This arrangement continues for 100s of folders. Inside Fd1 of each Folder x there are certain .bat files. I am looking for a way to extract a list of .bat files with entire path using Windows command line to a text file. With little experience of using command prompt I am clueless of how this can be achieved.

I want the output to be a list like this:

D:\Folder 1\Fd1\one.bat
D:\Folder 2\Fd2\two.bat

Can someone help me?

share|improve this question
up vote 16 down vote accepted

If I understand what you are looking for try

dir/s/b *.bat

If that works then redirect it into a text file....

dir/s/b *.bat > textfile.txt

You may also find it useful to have a list of command line switches for the DIR command.

share|improve this answer
Perhaps dir *.bat /s /b to limit output to contained .bat files? – kreemoweet Jan 17 '12 at 22:22

I'd suggest using the FOR command with the /R switch.

For example, to find all files in and under the current directory, use:

for /r %i in (*) do @echo %i

To start searching from an arbitrary directory, use this form of the command:

for /r "C:\TMP" %i in (*) do @echo %i

And lastly, to look for all batch files under the c:\bin directory, you could do this:

for /r "c:\bin" %i in (*.bat) do @echo %i

One point I should make, however, is that if you are using this command in a batch file, you will need to double the % signs, so these examples will become:

for /r %%i in (*) do @echo %%i
for /r "C:\TMP" %%i in (*) do @echo %%i
for /r "c:\bin" %%i in (*.bat) do @echo %%i

The use of i as the variable here is completely arbitary, and was first implanted in me in my FORTRAN days.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .