title: For loop - Notice a change in directory from a list of files
body: <p>I have a <code>mytextfile.txt</code> file that contains a list of files I want to process.</p>
  
  <h3>The list looks like this:</h3>
  
  <pre><code>"Z:\Folder 1\filename 01.doc"
  "Z:\Folder 1\filename 02.doc"
  "Z:\Folder 2\filename 01.doc"
  "Z:\Folder 2\filename 02.doc"
  "Z:\Folder 2\filename 03.doc"
  "Z:\Folder 3\filename 01.doc"
  </code></pre>
  
  <h3>My code:</h3>
  
  <pre><code>for /f "usebackq tokens=*" %%D in (mytextfile.txt) do (
   :: I only want to echo the directory every time it comes across a different one.
   echo Directory - "%%~dpD"
   :: Here is fine, I want to process the files now in the code below.
   echo Filename  - "%%~nD"
   )
  </code></pre>
  
  <h3>This outputs to the buffer:</h3>
  
  <pre><code>Directory - "Z:\Folder 1\"
  Filename  - "filename 01"
  Directory - "Z:\Folder 1\"
  Filename  - "filename 02"
  Directory - "Z:\Folder 2\"
  Filename  - "filename 01"
  Directory - "Z:\Folder 2\"
  Filename  - "filename 02"
  Directory - "Z:\Folder 2\"
  Filename  - "filename 03"
  Directory - "Z:\Folder 3\"
  Filename  - "filename 01"
  </code></pre>
  
  <h3>Whereas this is the desired output:</h3>
  
  <pre><code>Directory - "Z:\Folder 1\"
  Filename  - "filename 01"
  Filename  - "filename 02"
  Directory - "Z:\Folder 2\"
  Filename  - "filename 01"
  Filename  - "filename 02"
  Filename  - "filename 03"
  Directory - "Z:\Folder 3\"
  Filename  - "filename 01"
  
  </code></pre>
  
  <p>Notice how the directory is only output once.</p>