title: Is there a way to extract/replace just the last folder in the windows batch file path variable %1? trying to use it as part of the file name
body: <p>Seems a good place as any to ask</p>
  <p>So I want to assign a file name being processed by a batch file to:
  <code>LASTFOLDERIN%1PATHNAME-FOLDERNAME.rar</code> using the <code>%1</code> Windows sends me from the context menu.</p>
  <p>So far I'm able to ALMOST make it, I get so far as:</p>
  <pre><code>WinRAR.exe a -r -ep1 -u -m0 -y &quot;C:\Sorting\ %~p1-%~n1.rar&quot; &quot;%~1\*.*&quot;
  </code></pre>
  <p>Which returns:</p>
  <pre><code>\FULL(DIR1\DIR2\DIR3)PATH\-FOLDERNAME.RAR
  </code></pre>
  <p>But the problem is I get the FULL path (multiple directories), not just the very last one, also, I get the <code>\</code> that breaks the whole thing.</p>
  <p>Question is, is there a way to extract just the last folder in the path variable %~1 that I get from the windows context menu argument?</p>
  <p>Or if not, can I somehow replace the <code>\</code> with <code>-</code> so I can rename the files manually later? to get something like this: <code>-DIR1-DIR2-DIR3-FOLDERNAME.RAR</code></p>
  <p>Any help would be greatly appreciated, I'm stuck here.</p>
  <p>PS I'm sending <code>%V</code> to the batch file, since <code>%1</code> did all kinds of weird things.</p>