Fix Computer Online Help

Save Files and Folders List Structure Into a Text File Using Command Prompt

Have you encounter the scenario where your friend or relative has require you to list out the files and folders in a certain directory? And going thru the individual folders and taking screenshot is definitely not a feasible solution.

For instance, they have loaned you their external hard disk and requires you to list out the data in there.

Here a simple way to list out the files and folders in less than 3 min!.

Setup Scenario

For instance, in T drive, i have a “Test” folder. In this “Test” folder, there is one subfolder called “test2” and a file called “hello.txt

And in the “test2” folder, there is a “welcome.txt” and another subfolder called “test3

Hence our directory and file listing will look like the following

 

Test Hello.txt
test2 welcome.txt
test3

 

We can use the command prompt (cmd) to pull out the folders and files list in these directories.

  1. Open up command prompt
  2. navigate to the folder, in my scenario, it will T Drive, test folder.
  3. Once at the folder, type in “dir > file.txt
  4. A new file called file.txt will be created in the “test” folder. Open it and you should see the following

Directory of T:\test

Jun/23/2019 10:47 PM <DIR> .
Jun/23/2019 10:47 PM <DIR> ..
Jun/23/2019 10:38 PM 0 hello.txt
Jun/23/2019 10:44 PM <DIR> test2
2 File(s) 0 bytes

Did you notice that the command only displays what it sees in the “test” folder? What happen if you wish to list out the contents in the subfolders? In our current setup, the content in test2 folder has not been listed.

To list out all the folders and files in a directory to a txt file

Instead of typing “dir > file.txt“, type this in “dir /s “file.txt

And the result will be

Directory of T:\test

Jun/25/2019 10:47 PM <DIR> .
Jun/25/2019 10:47 PM <DIR> ..
Jun/25/2019 11:02 PM 0 file.txt
Jun/25/2019 10:38 PM 0 hello.txt
Jun/25/2019 11:02 PM <DIR> test2
2 File(s) 0 bytes

Directory of T:\test\test2

Jun/25/2019 11:02 PM <DIR> .
Jun/25/2019 11:02 PM <DIR> ..
Jun/25/2019 11:02 PM <DIR> test3
Jun/25/2019 10:38 PM 0 welcome.txt
1 File(s) 0 bytes

Directory of T:\test\test2\test3

Jun/25/2019 11:02 PM <DIR> .
Jun/25/2019 11:02 PM <DIR> ..
0 File(s) 0 bytes

Total Files Listed:
3 File(s) 0 bytes

 

 

Did you notice that the timestamp is included in the notepad? If timestamp is not needed, you may trim the file by typing this “dir /b /s > file.txt

You will see a listing without any formatting

T:\test\file.txt
T:\test\hello.txt
T:\test\test2
T:\test\test2\test3
T:\test\test2\welcome.txt

 

 

Personally i do not like this view, as to the end user, we are not able to tell that “test3” is a folder, based on the displayed view.

If i were to create another folder called “zzz” in test2, the view gets worse!

To give you an idea, this is the structure created.

If i were to run the “dir /b /s > file.txt” command, this will be what i see.

T:\test\file.txt
T:\test\hello.txt
T:\test\test2
T:\test\test2\a
T:\test\test2\test3
T:\test\test2\welcome.txt
T:\test\test2\zzz

The command without “/b” looks more organised personally.

 

Hopefully this page has allow you to easily list and print out the files and folders in the directory.

 

Exit mobile version