List all files in all subfolders

33

13

In windows, is there any way to get a list of all files in a folder, including all the files within all the subfolders?

Edward Wong Hau Pepelu Tivrusk

Posted 2009-08-31T07:53:25.617

Reputation: 453

Answers

37

List all Files Recursively

C:\>dir /s

To save them to a file

C:\>dir /s /b>filelist.txt

View them a page at a time

C:\>dir /s | more

Nifle

Posted 2009-08-31T07:53:25.617

Reputation: 31 337

3Since the question doesn't mention directories, it should be dir /a-d /b /s. – jiggunjer – 2016-10-07T03:11:02.287

@adolfgarlic ctrl+a shift right click -> copy as path – Zaider – 2017-02-22T20:38:58.007

2@Workshop Alex: Because 1) recursive dir is just a little bit faster if it doesn't have to check any conditions; 2) it lets you save the names into a file. – user1686 – 2011-01-26T11:01:17.303

3Well, okay... This will work too. Just wondering why no one uses the standard Search function of Windows for this. :-) – Wim ten Brink – 2009-08-31T10:03:02.420

4@WimtenBrink: and how are you going to send windows search to another user? – adolf garlic – 2012-06-26T08:53:03.937

1You dont need to pipe to more, you just need the /p switch (does the same thing) – Keltari – 2013-05-01T18:37:23.890

Remember the /a switch to include hidden files – Canadian Luke – 2013-05-08T05:01:34.920

15

Try tree /f. This should output the entire structure.

alex

Posted 2009-08-31T07:53:25.617

Reputation: 16 172

it does have the best structure. can it be saved as a text file or html file? – xypha – 2016-09-11T07:58:08.083

tried tree /f>filelist.txt & it worked. – xypha – 2016-09-11T08:00:49.480

1Which will be displayed as a tree, not a list. – Joey – 2009-08-31T08:29:58.333

You don't think the OP would consider that result a list? – hyperslug – 2009-08-31T08:59:11.380

2I thought the tree command would have the best formatting, allowing you to clearly see the level of the subfolders. – alex – 2009-08-31T09:25:18.440

5

You will get UnixUtils at sourceforge, that will give you find.exe.

You can then do the following for list of all files with folder paths.

cd Path\to\folder
find.exe . -type f

There are other forms of the Unix command that may be useful for you.
The output is more search-able compared to the native dir and tree commands.


Updated with input from Johannes.
In the cmd.exe shell

dir /b /s

works quite well for a recursive listing in the Widows formatted form,
(so you see "C:\" and the reverse slashes, '\').
I completely missed the "\b" in Nifle's answer! (+1 for that now).

nik

Posted 2009-08-31T07:53:25.617

Reputation: 50 788

No need to install anything here, as dir is perfectly capable of this. – Joey – 2009-08-31T08:30:34.887

1@Johannes, have you compared a Unix find output with a DOS dir /s or tree for that matter? – nik – 2009-08-31T09:36:27.373

1Have you ever used dir /b? :-) – Joey – 2009-09-02T05:13:31.210

@Johannes, actually I cannot remember if I did that in the DOS 6.22 days. Got more used to find and with Cygwin, never tried the dos commands (actually took me a moment to open cmd shell and avoid /usr/bin/dir to try that option. But, it does work; glad to learn that :-) – nik – 2009-09-02T06:27:12.997

2

Why so complex? Press Windowskey+F to start the "File Search" in Windows. On the left, go to "Look in" and select the option at the bottom called "Browse...". Select the (sub)folder where you want to search in. Enter "*" (without the quotes) in the "All or part of the file name" editbox and start the search. Get some coffee when you're searching on a big disk with lots of data and just wait for this explorer-based search engine to show you a complete list. You can search it, open files directly and even narrow your search if need be.

Why do people forget this default search behaviour of Windows?

Wim ten Brink

Posted 2009-08-31T07:53:25.617

Reputation: 1 815

@Wim: Your 5-step process (Win+F, Browse, Subfolder, *, Start) is much slower than just typing "dir/s" (for a typist who types over 100 words per minute, and is used to doing stuff at a command prompt, so it is frequently pre-opened). Also, the process you mention has changed w/ Windows versions, while "dir/s" has been consistent. Also, your process requires pressing Win+F, which isn't always easy. Sometimes, even if a keyboard has the Windows key, that key may be more difficult to use, such as in Remote Access scenarios where the key might be used by the local computer instead of the remote – TOOGAM – 2015-10-03T13:06:05.837

2Note that this will (on Win XP at least) search all ZIP files in all subfolders as well. Which will be horribly slow. Which probably isn't what you want. Which can't be easily switched off. If there are no ZIP files, I agree that this is the best approach. – Martin – 2011-01-26T09:49:18.080

3because it is not 1337? :-) – Natrium – 2009-08-31T13:14:02.843

13You would have a hard time getting that in a text file, for example. – Joey – 2009-09-02T05:14:11.973

True, but why would someone wants it in a text file? :-) – Wim ten Brink – 2009-09-02T07:30:16.893

1

I find this batch file every useful

DragDropListFile.bat

@ECHO OFF
SET targetPath="%~1"
SET ToolPath=%~dp0

dir %targetPath% /b /s /a-d > "%ToolPath%list.txt"

Usage: Just drag the folder and drop it on the file DragDropListFile.bat, then a file called list.txt, which contains what you want, is created.

If you don't like drag & drop, try this batch file

ListFile.bat

ECHO OFF

SET crtPath=%~dp0

dir "%crtPath%" /b /s /a-d > list.txt

Usage: put the file ListFile.bat in the folder you want to list files, then run the file ListFile.bat, then a file called list.txt, which contains what you want, is created.

123iamking

Posted 2009-08-31T07:53:25.617

Reputation: 357

0

dir /s /w >files.txt will get you most of the way there. It will keep the extensions. Then open files.txt in a text editor and either

  • sort all the lines and delete the superfluous ones
  • or remove them with a find and replace operation or 2.
    • The regex ^ +\d+ File.+\r\n\r\n Dir.+\r\n\r\n got rid of the gaps and folder details between the individual folder files listings for me in Notepad++.
  • Then just trim the top & tail of the text file.

CAD bloke

Posted 2009-08-31T07:53:25.617

Reputation: 801