title: Batch file that counts the number of files in EVERY folder in a directory, and outputs results to a text file
body: <p>What I'm trying to do is make a batch file that'll recursively go into every folder and count the number of files in each folder. However, I've spent the last hour trying various things and it isn't working.  </p>
  
  <p>I want the output to look like:
  X:Y where X is the folder name and Y is the # of files in X.  </p>
  
  <pre><code>setlocal EnableDelayedExpansion
  set current=blank
  FOR /D %%G in ("*") DO set current=%%G &amp;&amp; call:count
  
  :count
  set count=0
  for %%A in (*) do set /a count+=1
  echo !current!:!count!&gt;&gt;"D:\User\Some\Directory\count.txt"
  </code></pre>
  
  <p>But this doesn't work. The output is giving the same number for each folder. The number it's outputting is the number of files in the directory itself, which I think is the problem.  </p>
  
  <p>Specifically, if I'm in <code>C:\User\Example</code> and it has three folders, A, B, and C, I want the number of files in <code>C:\User\Example\A</code> and so on, but it's giving me the number of files in <code>C:\User\Example</code>. Hope that makes sense.  </p>
  
  <p>Note: In my use case, the folders will not contain sub-directories.  </p>