31

I was hoping to be able to use the

tree /F /A > "desktop"\file.txt

command to output only text files. Currently as is, it outputs every file extension.

Does anyone know of an easy way to do this?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
trippedoutfish
  • 357
  • 1
  • 4
  • 8

5 Answers5

45

Tree accepts only a few command line parameters:

c:\>Tree /?
Graphically displays the folder structure of a drive or path.

TREE [drive:][path] [/F] [/A]

   /F   Display the names of the files in each folder.
   /A   Use ASCII instead of extended characters.

None of the indicated parameters are a file mask or filter.

You can use dir with the proper switches, and redirect the output to a text file. You'll get the full path name to the files, but you can filter that out in later processing if need be with a for loop:

C:\>dir *.txt /s /b > filelist.txt
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Note - the command prompt was locked down on the server I was trying the tree function on. It worked best to use the 'dir' command inside a .cmd file. – John M Apr 06 '16 at 02:30
13

It's actually not that hard to get your desired TREE output using FINDSTR regular expressions. :-)

tree /f /a | findstr /ri /c:"^[^| ]" /c:"^[| ]*[+\\]" /c:"\.txt$"
dbenham
  • 127,446
  • 28
  • 251
  • 390
4

Note: that tree command does not order the output by name!

Instead you can use this approach:

dir /b /s /ad /on c:\ > c:\file.txt

Result looks like less nice but

reference

this solution found on Superuser by pbies

Community
  • 1
  • 1
1

Another simple option: Go to the directory you want to list out, type in CMD so you are already in the right place, then:

tree /a /f>"output.doc"

That will put it into a word doc, easier to edit and format from there.

-1

Simpler.

You just need to export your result like this: tree /a /f >"toto.rtf"

Then you open the file with Word and choose MS DOS convert.

Leonardo Alves Machado
  • 2,747
  • 10
  • 38
  • 53