title: batch: get relative filepath of files
body: <p>I need to get the relative filepath of files with bat.</p>
  
  <p>The folder structure</p>
  
  <pre><code>file.bat
  - folder1
  -- subfolder1
  ----- abc.image
  ----- def.image
  -- subfolder2
  ---- more.image
  - folder2
  -- subfolder1
  ---- alsoimages.image
  -- subfolder2
  </code></pre>
  
  <p>For abc.image, I'd like to get the name of the folder (here e.g. folder1) and the combination folder+subfolder (here e.g. folder1/subfolder1)</p>
  
  <p>I looked at this post: <a href="https://stackoverflow.com/questions/8487489/batch-programming-get-relative-path-of-file">batch programming - get relative path of file</a>
   but I cant make it work for me. The output keeps giving me too many hierachies.</p>
  
  <p>What I want to do ultimately is this:</p>
  
  <pre><code>set "prefix=td"
  set "file=list_of_images.xml"
  
  echo ^&lt;?xml version="1.0"  encoding="UTF-8" standalone="yes"?^&gt; &gt; %file%
  echo ^&lt;files^&gt; &gt;&gt;  %file%
  
      for /r %%x in (*.image) do ( 
  
          echo ^&lt;file folder="(here e.g. folder1)" subfolder="(here e.g. folder1/subfolder1)" id="%prefix%%%~nx" type="image" /^&gt; &gt;&gt;  %file%
      )
  
  echo  ^&lt;/files^&gt; &gt;&gt;  %file%
  </code></pre>
  
  <p>Thanks for help and tips!</p>