user1760178
user1760178

Reputation: 6717

Command to list all files in a folder as well as sub-folders in windows

I tried searching for a command that could list all the file in a directory as well as subfolders using a command prompt command. I have read the help for "dir" command but coudn't find what I was looking for. Please help me what command could get this.

Upvotes: 315

Views: 1967318

Answers (7)

Misaal D'souza
Misaal D'souza

Reputation: 111

An addition to the above answers :

To print specific file present in the folders/sub-folders for eg : If you want to list just the csv files then :

dir /b/s/A-D/o:gn *.csv >list.txt

If you want to also include .xlsx files then the code is :

dir /b/s/A-D/o:gn *.csv *.xlsx >list.txt

You can mention more file types in the same way.

P.S Got to know this one from chatgpt :P

Upvotes: 2

Tabish Zaman
Tabish Zaman

Reputation: 292

The below post gives the solution for your scenario.

**dir /s /b /o:gn**

/S Displays files in specified directories and all subdirectories.

/B Uses bare format (no heading information or summary).

/O List by files in sorted order.

:gn, g sorts by folders and then files, and n puts those files in alphabetical order.

Just for all files except long path, write the following command:

**dir /b /o:gn**

For Tree: write in your cmd

tree /f

Upvotes: 5

user1985027
user1985027

Reputation:

The below post gives the solution for your scenario.

dir /s /b /o:gn

/S Displays files in specified directory and all subdirectories.

/B Uses bare format (no heading information or summary).

/O List by files in sorted order.

Then in :gn, g sorts by folders and then files, and n puts those files in alphabetical order.

Upvotes: 469

Mr.X
Mr.X

Reputation: 31345

If you simply need to get the basic snapshot of the files + folders. Follow these baby steps:

  • Press Windows + R
  • Press Enter
  • Type cmd
  • Press Enter
  • Type dir -s
  • Press Enter

Upvotes: 9

Laszlo Lugosi
Laszlo Lugosi

Reputation: 3829

An addition to the answer: when you do not want to list the folders, only the files in the subfolders, use /A-D switch like this:

dir ..\myfolder /b /s /A-D /o:gn>list.txt

Upvotes: 87

Bruno
Bruno

Reputation: 5822

An alternative to the above commands that is a little more bulletproof.

It can list all files irrespective of permissions or path length.

robocopy "C:\YourFolderPath" "C:\NULL" /E /L /NJH /NJS /FP /NS /NC /B /XJ

I have a slight issue with the use of C:\NULL which I have written about in my blog

https://theitronin.com/bulletproofdirectorylisting/

But nevertheless it's the most robust command I know.

Upvotes: 7

Somnath Muluk
Somnath Muluk

Reputation: 57846

If you want to list folders and files like graphical directory tree, you should use tree command.

tree /f

There are various options for display format or ordering.

Check example output.

enter image description here

Answering late. Hope it help someone.

Upvotes: 201

Related Questions