title: Batch file that can index and rename files in multiple subfolders, resetting the index every time the loop goes into a new folder
body: <p>I am in the process of writing a batch file that can quickly run through a root folder, We'll just say "C:\SomeMusic\" that has a lot of subfolders and files in it. What I'm looking to do is to rename <strong>just</strong> the files in each folder, but in a sequential way (ex. somefile1.ext, somefile2.ext ...)</p>
  
  <p>I have this right now, but I do not know how to reset my counter if the loop goes into a new directory</p>
  
  <pre><code>SET COUNT=0
  setlocal ENABLEDELAYEDEXPANSION
  FOR /R %%X IN (*.mp3) DO (
      SET /A COUNT=!COUNT!+1
      SET FN=%%~nxX
      ECHO Renamed "!FN!" to "song!COUNT!.mp3"
      REN %%X song!COUNT!.mp3
  )
  :EOF
  endlocal
  PAUSE
  </code></pre>
  
  <p>On a quick sidenote: If I run the Rename command like this, it will name the files "song1.mp3", "song2.mp3" "song3.mp3" regardless of what their name used to be?</p>