How to recursively list files in a Windows directory and export it directly into CSV format (Powershell one-liner)

The following short example shows how to export the list of file names (basenames) and extensions inside the directory as a comma-separated Excel file.

Simply open PowerShell (run/powershell) and run the following command:

get-childitem -path c:\0.test -Recurse | where {!$_.PSIsContainer} | select-object BaseName,Extension | export-csv -notypeinformation -path c:\0.test\files.csv | % {$_.Replace(‘”‘,”)}

Point the:

  • the first path to the directory you want to scan (highlighted in red)
  • the second path to where you want to save the CSV (highlighted in green)

It’ll do the job for you and the CSV result would look something like this in Excel:

 

Facebook Comments