Dir is a command used to list all directories and files of a folder.

It will not list all subdirectories.

Syntax

dir options

dir command without options lists out all folders of a current directory.

B:\parent>dir
 Volume in drive B has no label.
 Volume Serial Number is 0A9B-F96C

 Directory of B:\parent

01-09-2021  14:43    <DIR>          .
01-09-2021  14:43    <DIR>          directory1
01-09-2021  14:42    <DIR>          directory2
01-09-2021  14:43    <DIR>          directory3
               0 File(s)              0 bytes
               4 Dir(s)  72,082,702,336 bytes free

Recursive directory listing

The /s option with dir command elements lists out all file and folder names and subfolders of a current directory.

B:\parent>dir /s
 Volume in drive B has no label.
 Volume Serial Number is 0A9B-F96C

 Directory of B:\parent

01-09-2021  14:43    <DIR>          .
01-09-2021  14:43    <DIR>          directory1
01-09-2021  14:42    <DIR>          directory2
01-09-2021  14:43    <DIR>          directory3
               0 File(s)              0 bytes

 Directory of B:\parent\directory1

01-09-2021  14:43    <DIR>          .
01-09-2021  14:43    <DIR>          ..
01-09-2021  14:43    <DIR>          directory1-1
01-09-2021  14:43    <DIR>          directory1-2
               0 File(s)              0 bytes

 Directory of B:\parent\directory1\directory1-1

01-09-2021  14:43    <DIR>          .
01-09-2021  14:43    <DIR>          ..
               0 File(s)              0 bytes

 Directory of B:\parent\directory1\directory1-2

01-09-2021  14:43    <DIR>          .
01-09-2021  14:43    <DIR>          ..
               0 File(s)              0 bytes

 Directory of B:\parent\directory2

01-09-2021  14:42    <DIR>          .
01-09-2021  14:43    <DIR>          ..
               0 File(s)              0 bytes

 Directory of B:\parent\directory3

01-09-2021  14:43    <DIR>          .
01-09-2021  14:43    <DIR>          ..
01-09-2021  14:43    <DIR>          directory3-1
01-09-2021  14:43    <DIR>          directory3-2
               0 File(s)              0 bytes

The above command gives header and footer information.

List files directories and subfolders recursively

It is another way of printing files and subfolder information.

B:\parent>dir /b /s
B:\parent\directory1
B:\parent\directory2
B:\parent\directory3
B:\parent\directory1\directory1-1
B:\parent\directory1\directory1-2
B:\parent\directory3\directory3-1
B:\parent\directory3\directory3-2

if you want file names in sorted order, You can use the sort order option as described below

dir /s /b sortorder:N