List of file extension in a directory

Question

How to get distinct list of file extension in a directory and sub directory in windows?

Option 1: List of file extension

  1. Open notepad and paste “script 1” into this file
  2. Save file with “.bat” extension
  3. Open cmd in the directory that has “.bat” file
  4. Run “script 2” to output distinct list of file extension into “output.txt” file.
  5. Replace “path” in script 2 with actual path you want to traverse
Script 1
@echo off

set target=%~1
if "%target%"=="" set target=%cd%

setlocal EnableDelayedExpansion

set LF=^


rem Previous two line left blank for LF to work

for /f "tokens=*" %%i in ('dir /b /s /a:-d "%target%"') do (
    set ext=%%~xi
    if "!ext!"=="" set ext=FileWithNoExtension
    echo !extlist! | find "!ext!:" > nul
    if not !ERRORLEVEL! == 0 set extlist=!extlist!!ext!:
)

echo %extlist::=!LF!%

endlocal
Script 2
batchfile "path" >output.txt

Option 2:

  1. Create new folder
  2. Open power shell in this folder (shift + right mouse click)
  3. Run following command to output distinct list of file extension in a directory in output.txt file
  4. Replace “\\path” with directory path that you want to traverse
Get-Childitem "\\path" -Recurse | WHERE { -NOT $_.PSIsContainer } | Group Extension -NoElement | Sort Count -Desc > output_ps.txt
output.txt

Other useful link

Windows file extensions
Jupyter start up folder
Highlight Excel rows