How To List Files In Command Prompt In Windows?

Windows command prompt MS-DOS provides the dir command in order to list files. The dir command provides different features while listing the files. Actually, the dir command does not only list files it also lists directories too. In this tutorial, we will learn how to list files in command prompt in different ways like specific extension, recursive list, etc.

List Files with dir Command

The dir command is a very old command provided by MS-DOS. The dir command is used to list files and folders. Without providing any option to the dir command prints all files and folders in the current directory.

List Files and Folders with dir Command

Only files can be listed by using the /b and /a-d options with dir command. The /b command use bare format where only file names are listed. Also /a-d option is used to not list directories where only files are listed.

dir /b /a-d
List Files with dir Command

Alternatively the bare formattin can be disabled without providing the /b option like below.

dir /a-d
List Files with dir Command

List Files Located in Different Path

Files located different than current working directory or different path can be listed. The path is provided to the dir command as parameter. In the following example we list files located in the C:\Users\ismail\Desktop .

dir C:\Users\ismail\Desktop
List Files in Different Path

Alternatively only files can be listed like below.

dir /b /a-d C:\Users\ismail\Desktop
List Files in Different Path

List File Types

There are a lot of different file types. The dir command can be used to list files according to their types or extension. The extension is used to specify file type. Generally the file extension is specified by using glob operator like *.txt . In the following example we list only zip files using the *.zip .

dir *.zip

Alternatively we can list zip files located other directories by providing the directory path.

dir C:\Users\ismail\Desktop\*.zip

List All Files Recursively

By default, the dir lists files located in the current working directory or provided path. It does not list the child directories and child files located in these directories. The /S option can be used to list all files located in the child directories.

dir /S

We can specify the path to list another than the current working directory recursively.

dir /S C:\Users\ismail\Desktop\

We can list specific file types recursively. In the following exmaple we list all *.sys files located under the Desktop and its child directories.

dir /S C:\Users\ismail\Desktop\*.sys

Leave a Comment