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.
04 Answers
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.
I need to list all files from folders and subfolders and export to notepad or Excel.
From the command line:
dir /a /s /b > filelist.txt /aShow all files/sInclude all subfolders./bBare format (no heading, file sizes or summary)
Open filelist.txt in notepad++ or excel.
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- dir - Display a list of files and subfolders.
You can this PowerShell script which will list down all the folders subfolders and files and write it to csv file.
$rootPath = "D:\data" $getFilesfromRootDirectory = Get-ChildItem -Path $rootPath | %{$_.FullName} $csvFilename = "D:\Output\outputs.csv" #Output will be written to csv file function get_files_under_folders($value) { $getFiles = Get-ChildItem -Path $value | %{$_.FullName} foreach ($value in $getFiles) { if(checkFileorFolder($value)) { echo "$value" >> $csvFilename Write-Host $value get_files_under_folders($value) } else { Write-Host $value echo "$value" >> $csvFilename } } } function checkFileorFolder($value) { $CheckFile = Test-Path -Path $value -PathType Container return $CheckFile } foreach($value in $getFilesfromRootDirectory) { if(checkFileorFolder($value)) { Write-Host $value get_files_under_folders($value) } else { Write-Host $value echo "$value" >> $csvFilename } } DavidPostill answer is quite perfect, but I would like to add something to make it more easy.
Copy this to notepad:
dir /a /s /b > filelist.txt
Save that into folder which file names you want collect with .bat extension aka File > Save As > All Files > WHATEVER.bat
You can just save it in one place and then copy/paste it to folder where needed
/a Show all files
/s Include all subfolders.
/b Bare format (no heading, file sizes or summary)
Open filelist.txt
- one question related to this. How to exclude files with specific extensions ?
.