title: Batch file : how to get a specific part of a folder path
body: <p>I'm currently looping threw the subfolders of a known directly. I would like to grab the folder that contains the file I'm looking for, but only that folder's name, not the whole path, and preferably in a different variable to be use later on in the batch file ... </p>
  
  <pre><code>pause
  CD c:\%username%\testFolder\Program\OLD\
  
  For /R %%G in (test.t?t) do Echo %%G
  
  pause
  </code></pre>
  
  <p>Now, this shows me the file I'm looking for : C:\User\testFolder\Program\OLD\myfile\exemple1\test.txt</p>
  
  <p>what I would like is to replace the Echo %%G to set in a variable the "unknown" folders and subfolder, something along the line of </p>
  
  <pre><code>For /R %%G in (test.t?t) do set var1 = myfile\exemple1
  </code></pre>
  
  <p>anyone can point to what I'm missing ?</p>