title: Batch script to recursively rename files and folders
body: <p>I require a windows batch script to recursively rename files and folders with the name of the parent folder and add a prefix/suffix.</p>
  <p>I have 2 folders <code>fol1</code> and <code>fol2</code>, with the following directory structure:</p>
  <pre><code>fol1
    ├───fol1.1
    │   └───text.txt
    ├───fol1.2
    │   └───text.txt
  fol2
    ├───fol2.1
    └───fol2.2
  </code></pre>
  <p>I want the tree renamed as:</p>
  <pre><code>lon_fol1_par
    ├───lon_fol1.1_par
    │   └───fol1.1_text.txt
    ├───lon_fol1.2_par
    │   └───fol1.2_text.txt
  lon_fol2_par
    ├───lon_fol2.1_par
    └───lon_fol2.2_par
  </code></pre>
  <p>The code that helped me renaming is as follows:</p>
  <pre><code>FOR /F &quot;tokens=1 delims=&quot; %%A IN ('DIR /B /S /A:D') DO (
  
     FOR /F &quot;tokens=1 delims=&quot; %%B IN ('DIR /B /A:-D &quot;%%A&quot;') DO (
      pushd %%A
      FOR %%I IN (.) DO RENAME &quot;%%A\%%B&quot; &quot;&lt;Name I want&gt;&quot;%%~xB
      popd ..
    )   
  )  
  </code></pre>