title: Batch files: Get absolute path
body: <p>I receive a file that contains the following:</p>
  
  <pre><code>\direcotry1\directory2\directory3\file1
  \direcotry1\file2
  \direcotry1\directory2\directory3\directory4\file3
  \direcotry1\file4
  \direcotry1\directory2\file5
  file6
  </code></pre>
  
  <p>The amount of files in the file and the amount of directories are variable.</p>
  
  <p>What I need is the path only.</p>
  
  <pre><code>\direcotry1\directory2\directory3\ for file1
  \direcotry1\ for file2
  \direcotry1\directory2\directory3\directory4\ for file3
  \direcotry1\ for file4
  \direcotry1\directory2\ for file5
  and nothing for file6
  </code></pre>
  
  <p>I used the variable %%~pi which works for all except for the last one. For the last one it returns \cft\<br>
  I guess the \cft\ is returned as the program that is calling the bat file launches it from there.</p>
  
  <pre><code>FOR /F %%i in (test.txt) DO (
    echo %%~pi
    command1
    command2
  )
  </code></pre>
  
  <p>Does anyone know how I can avoid that the batfile returns \cft\? I want the bat to return nothing when there's no path.</p>
  
  <p>Thanks a lot in advance for your help.</p>