title: How to get a Part of the Directory path in a batch file
body: <p>I have a BAT file in a directory </p>
  
  <pre><code>D:\dir1\dir2\getpath.bat
  </code></pre>
  
  <p>when i run the bat with the below code it prints </p>
  
  <pre><code>D:\dir1\dir2\
  </code></pre>
  
  <p>i want only the path <code>D:\dir1\</code></p>
  
  <p>The directory structure is not fixed , need the complete directory path other than the current directory in which BAT file resides.</p>
  
  <pre><code>@echo off
  SET SUBDIR=%~dp0
  ECHO %SUBDIR% 
  </code></pre>
  
  <p>tried using delims in a for loop but it didnt help.</p>