1

i have a variable like this:

set file=c:\dir\foo\bar\file.txt

how can i get just the path-part into another variable?

echo %pathpart%

should give c:\dir\foo\bar\

thanks!

clamp
  • 33,000
  • 75
  • 203
  • 299
  • possible duplicate of [How do I get the equivalent of dirname() in a batch file?](http://stackoverflow.com/questions/778135/how-do-i-get-the-equivalent-of-dirname-in-a-batch-file) – Matthew Whited Jun 01 '10 at 16:07
  • Since some people coming here are wanting to get the filename part and not the directory, to save you time: use %~np to get only the filename and extension. For example, %~nx1 returns the value of %1 but without the drive letter or path (useful for drag-and-drop batch files). Without the extension is `~n`. – Aaron D May 15 '15 at 04:16
  • 1
    This answer provides a list of batch-script variable modifiers: http://stackoverflow.com/a/3215539/1960180 – Aaron D May 15 '15 at 04:17

1 Answers1

1

How do I get the equivalent of dirname() in a batch file?

Community
  • 1
  • 1
Anton
  • 2,653
  • 1
  • 16
  • 7