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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top