How to determine file extension based on file path in LaTeX?

I am trying to write a LaTeX package that uses the minted \ inputminted package command. The my \ mycommand command takes two parameters: the first is the path to the file, and I want to pass the file extension to the \ inputminted command:

\newcommand\mycommand[2]{
  \inputminted{#1}{...}
}

Please note that the above will not work as the full path is passed to \ inputminted.

Example:

\mycommand{/path/to/Test.java}{blah}

should cause

\inputminted{java}{...}
+5
source share
1 answer

In your package, use the \ filename @parse function

\filename@parse{/path/to/Test.java}

then you can access the results with

\filename@base
\filename@ext

So in your case

\inputminted{\filename@ext}{...}
+2
source

All Articles