Skip navigation

JSI Tip 9197. How can I list the file extensions that are present on a disk drive or folder?


Using only standard commands, I have scripted UsedExtensions.bat to display the file extensions that are used on a specified drive or folder.

The syntax for using UsedExtensions.bat is:

UsedExtensions Object

Where Object can be any valid file system object, like D: or "C:\Documents and Settings" or \\ServerName\ShareName.

The output is displayed on the console, like:

""
".dll"
".msstyles"
".ppt"
".txt"
".ZIP"
or you can redirect it to a file using UsedExtensions Object>FileName.

UsedExtensions.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: UsedExtensions Object&goto :EOF
setlocal
set drv=%1
set fn=%TEMP%\UsedExtensions_%RANDOM%
for /f "Tokens=*" %%a in ('dir %drv% /b /s /a-d /a') do (
 if not exist "%fn%%%~xa" @echo.%%~xa>"%fn%%%~xa"
)
for /f "Tokens=*" %%a in ('dir "%fn%*.*" /b') do (
 @echo "%%~xa"
 del /q "%TEMP%\%%a"
)
endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish