How to use dynamically generated filenames in \IfFileExists?

by CarpeDiemKopi   Last Updated September 12, 2019 00:23 AM

I have a file 0012in the directory of the following tex file. I want to check the existence or non-existence of files inside the \forloop from 11 to 13.

\documentclass{article}
\usepackage{numprint}
\newcounter{ct} 
\newcommand{\fileno}{\npfourdigitnosep\nplpadding{4}\numprint{\arabic{ct}}}
\usepackage{forloop}
\setlength\parindent{0pt}
\begin{document}
    \forloop{ct}{11}{\value{ct} < 14} { 
        % \IfFileExists{0012} {
        \IfFileExists{\fileno} {
           fileno: "\fileno{}" exists! \\
        } {       
           fileno: "\fileno{}" doesn't exist! \\
        }
    }    
\end{document}

I get this compile error:

! Incomplete \iffalse; all text was ignored after line 15.
<inserted text>
                \fi

I have no compiler error if I switch to

\IfFileExists{0012} 

How can I check the existence of files with my \fileno macro?

output:

fileno: ”0011” exists!
fileno: ”0012” exists!
fileno: ”0013” exists!

I want this output:

fileno: ”0011” doesn't exist!
fileno: ”0012” exists!
fileno: ”0013” doesn't exist!
Tags : macros tex-core


Related Questions


How to define phantoms for depth and height?

Updated June 28, 2015 18:10 PM


Explode arguments in argument list

Updated May 16, 2016 08:09 AM

How is \unexpanded defined?

Updated December 29, 2016 08:09 AM