# The currfile Package

I am using a number of input files within 2 directories:

dirA/ which has a file dirA/A.tex which inputs dirA/dirB/B.text

I'm using currfile to print out the currfiledir which gives me

dirA/dirB


is there anyway I can make it just give me dirB?

This can be done with the help of the xstring package and its macro \StrBehind.

In your case, if \currfiledir returns dirA/dirB/, then

\StrBehind{\currfiledir}{/}


will return dirB/.

In fact the result is "all the stuff behind /"

If you also want to remove the trailing / you can use

\StrBehind{\currfiledir}{/}[\currfilesubdir]
\StrBefore{\currfilesubdir}{/}


In this way you first save the result of \StrBehind in the macro \currfilesubdir and then you use it as the argument of \StrBefore which does the opposite of \StrBehind. The result will be dirB.

Obviously this only works if you have your file in a subdirectory of second level like dirA/dirB/.

If your file is in a deeper subdirectory (let's say dirA/dirB/dirC/dirD/, you can opt for one of the following solutions to automate the whole process.

1. Print the subdirectory name without the trailing /

\newcommand{\currlastdir}{%
\StrCount{\currfiledir}{/}[\numberofdirs]%
\ifnum\numberofdirs=1\StrBefore{\currfiledir}{/}\else%
\StrBehind[\numexpr\numberofdirs-1\relax]{\currfiledir}{/}[\currfilesubdir]%
\StrBefore{\currfilesubdir}{/}\fi%
}


and then in your subdocument use

\currlastdir


\currfiledir


and you will get dirD printed.

2. Print the subdirectory name with the trailing /

\newcommand{\currlastdir}{%
\StrCount{\currfiledir}{/}[\numberofdirs]%
\ifnum\numberofdirs=1\currfiledir\else%
\StrBehind[\numexpr\numberofdirs-1\relax]{\currfiledir}{/}\fi%
}


and then in your subdocument use

\currlastdir


\currfiledir


and you will get dirD/ printed.

Do you mean something like this?

\def\currfiledir{dirA/dirB} % for example

\def\ignorefirstdir{\expandafter\ignorefirstdirA\currfiledir/\end}
\def\ignorefirstdirA#1/#2\end{\ifx^#2^\else\expandafter\ignorefirstdirB#2\end\fi}
\def\ignorefirstdirB#1/#2\end{#1}

Printing only second directory: \ignorefirstdir.