Windows – List all files from folders and subfolders in Windows Server 2003 and export it to notepad

command linewindows-server-2003

I have a server that has over 600 GB of data on one of the drives.

I need to list all the files from the folders and subfolders and export that to notepad or to Excel.

Best Answer

Quick and dirty in PowerShell:

C:\> dir -recurse | out-file X:\pathtofile.txt

This will output something similar to this:

    Directory: E:\Kodak\3500\PDFs\index\parts


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        8/10/2002  4:18 a.m.      40960 00000005.ddd
-a---       26/09/2002  7:55 a.m.     446464 00000005.did
-a---        8/10/2002  4:18 a.m.          0 00000005.mrg
-a---        8/10/2002  4:18 a.m.      17408 00000006.ddd
-a---        5/10/2002  3:19 a.m.     221184 00000006.did
-a---        8/10/2002  4:18 a.m.          0 00000006.mrg
-a---        8/10/2002  4:18 a.m.      17408 00000007.ddd
-a---        8/10/2002  3:48 a.m.     102400 00000007.did
-a---        8/10/2002  4:18 a.m.          0 00000007.mrg
-a---        8/10/2002  4:18 a.m.      16384 00000008.ddd
-a---        8/10/2002  4:18 a.m.      32768 00000008.did
-a---        8/10/2002  4:18 a.m.          0 00000008.mrg
-a---        8/10/2002  4:20 a.m.      52224 00000009.ddd
-a---        8/10/2002  4:18 a.m.     641024 00000009.did

If you add -name to the command somewhere after dir but before the | then you get the following:

PDFs\index\parts\00000005.ddd
PDFs\index\parts\00000005.did
PDFs\index\parts\00000005.mrg
PDFs\index\parts\00000006.ddd
PDFs\index\parts\00000006.did
PDFs\index\parts\00000006.mrg
PDFs\index\parts\00000007.ddd
PDFs\index\parts\00000007.did
PDFs\index\parts\00000007.mrg
PDFs\index\parts\00000008.ddd
PDFs\index\parts\00000008.did
PDFs\index\parts\00000008.mrg
PDFs\index\parts\00000009.ddd
PDFs\index\parts\00000009.did

You may also want to include a -force after the -recurse as this will show Hidden and System files as well.

Be warned, this file will be large. I ran this against the C:\ of my work computer and it generated a 45MB txt file. That's excluding all the folders my user account doesn't have access to.

Related Question