How to extract the directory from a passed filename in .bat files

  • Thread starter Thread starter Michael Moser
  • Start date Start date
M

Michael Moser

I want to write me a little batch file that gets passed the filename of
a .tex file and then invokes LaTeX on it:

e.g. it is called as:
mybatchfile C:\foo\bar.tex

it should then first switch to the directory of the file whose name it
got passed and then execute LaTeX on it, i.e.:
--------------------------
cd C:\foo
C:\Programs\MiKTeX\bin\latex C:\foo\bar.tex
--------------------------

How can one extract the directory from a filename in a batch file, i.e.
how do I derive the substring "C:\foo" from the passed parameter
"C:\foo\bar.tex" using cmd's built-in functions?

Michael
 
Back
Top