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



Michael Moser
07-10-2005, 12:13 AM
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

David Candy
07-10-2005, 12:13 AM
Type call or for in Help. %~dp1

--
----------------------------------------------------------

"Michael Moser" <michael-nospam.moser@nospam.freesurf.ch> wrote in message news:Ohf2Y05VFHA.3176@TK2MSFTNGP12.phx.gbl...
>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
>
>
>
>


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