Programming Field

Tree - DOS/Command Prompt Reference

Displays specified directory's subdirectories in tree format.

Syntax

tree[.com] [/A] [/F] [<directory>]

* The ‘Tree’ program has an extension ‘.com’ even in Windows 10.

Options

<directory>
Specifies the directory to display subdirectories. If omitted, the current directory is used.
/A
Uses ASCII characters for tree display. If /A is not specified, extended characters (such as ‘│├└─’) are used; if /A is specified, ‘|+\-’ are used.
* Used characters when /A is not specified may vary depending on the language.
/F
Displays not only subdirectories but also files onto the tree.

Details

Usage of Tree

This command outputs the directory tree as human-readable text like followings.

Folder PATH listing
Volume serial number is xxxx-xxxx
N:.
├─Document
│  ├─Backup
│  └─Download Files
├─Pictures
├─Video
└─Work
    ├─2010
    │  └─Event
    ├─2011
    └─2012

The second line represents the volume serial number of the drive where the directory exists, the third line represents the specified directory (or ‘Drive letter’ + ‘:’ + ‘.’ if omitted), and the fourth and subsequent lines represent subdirectories (and files if /F is specified). (In Windows 10. The format in the earlier versions or MS-DOS may vary.)

If ‘/A’ is specified, the output is like followings.

Folder PATH listing
Volume serial number is xxxx-xxxx
N:.
+---Document
|   +---Backup
|   \---Download Files
+---Pictures
+---Video
\---Work
    +---2010
    |   \---Event
    +---2011
    \---2012

If the directory contains no subdirectories, ‘No subfolders exist’ (or ‘No subdirectories exist’) will be printed.

This command does not display directories/files with Hidden file or System file attributes. To display those directories/files, the attributes need to be removed by using Attrib command. To confirm whether directories/files with Hidden file and/or System file attributes exist, use Dir command instead.

If the directory contains many subdirectories (and files if /F is specified), it may take much time to display. Also, the output may not fit on the screen. In this case, you can write the output to the file by using output redirection ‘>’, or use More command to control the output.

Samples

Sample 1

tree C:\WINDOWS | more

Displays subdirectory tree of ‘C:\WINDOWS’. In case it has many directories, displays one screen at a time by passing output to More with ‘|’.

Sample 2

tree /A /F D:\Document > d_doc.log

Outputs all subdirectories and files tree (excluding files/directories with Hidden file or System file attribute) in ‘D:\Document’ to the file ‘d_doc.log’ (using ‘>’ (redirection) to output to the file).

Note that this command may take much time due to enumerating all directories and files, and ‘d_doc.log’ may become a huge file.

See also