title: Batch Script - Displaying files and directory in sorted order
body: <p>So I'm trying to make my own dir command for cmd. So far it is working great, except I want to output the directories and files sorted by file extension, in the way </p>
  
  <pre><code>dir /o:ge
  </code></pre>
  
  <p>would display (folders first, then files sorted by file extension).
  So far, my code looks like this</p>
  
  <pre><code>@echo off
  
  rem Title
  echo.
  echo CURRENT DIRECTORY [%cd%]
  echo. 
  rem Directories
  for /d %%D in (*) do (
      echo [DIR] %%~nD
  )
  
  rem Files
  for %%F in (*) do (
      echo %%~nxF
  )
  @echo on
  </code></pre>
  
  <p>This produces:</p>
  
  <p><a href="https://i.stack.imgur.com/Np06y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Np06y.png" alt="Example"></a></p>
  
  <p>I'm not sure how to approach outputting the files sorted by file extension. I have searched the web and can't find a solution to this problem. I  do realize batch script is very limited, but I still want to try and implement this. I have thought of using a for loop and storing all the file extensions into an "array" (if that exists in batch), and then outputting them by </p>
  
  <pre><code>*.fileExtension
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>Cheers,
  Derek</p>