Here is a way with LaTeX3 macros
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\enableflags}{ m }
{
\karathan_enable_flags:n { #1 }
}
\NewDocumentCommand{\flags}{ O{} }
{
\karathan_flags:n { #1 }
}
\seq_new:N \g_karathan_enabled_flags_seq
\bool_new:N \l_karathan_flag_found_bool
\cs_new_protected:Npn \karathan_enable_flags:n #1
{
\seq_gset_from_clist:Nn \g_karathan_enabled_flags_seq { #1 }
}
\cs_new_protected:Npn \karathan_flags:n #1
{
\bool_set_false:N \l_karathan_flag_found_bool
\clist_map_inline:nn { #1 }
{
\seq_if_in:NnT \g_karathan_enabled_flags_seq { ##1 }
{ \clist_map_break:n { \bool_set_true:N \l_karathan_flag_found_bool } }
}
\bool_if:NF \l_karathan_flag_found_bool { \endinput }
}
\ExplSyntaxOff
\begin{document}
\section{Enabled \texttt{energy}}
\enableflags{energy}
\input{exercise.435.tex}
\input{exercise.436.tex}
\section{Enabled \texttt{entropy}}
\enableflags{entropy}
\input{exercise.435.tex}
\input{exercise.436.tex}
\section{Enabled \texttt{solid.body}}
\enableflags{solid.body}
\input{exercise.435.tex}
\input{exercise.436.tex}
\section{Enabled \texttt{energy}, \texttt{entropy}, \texttt{solid.body}}
\enableflags{energy, entropy, solid.body}
\input{exercise.435.tex}
\input{exercise.436.tex}
\end{document}
The \enableflags command receives as argument the list of flags you want to enable. Then \flags compares each item in its argument with this list. If no match is found, the file is closed and no more input from it is accepted (with \endinput).

If you want an and and not an or of the flags, here's how you can define the macro \karathan_flags:n:
\cs_new_protected:Npn \karathan_flags:n #1
{
\bool_set_true:N \l_karathan_flag_found_bool
\seq_map_inline:Nn \g_karathan_enabled_flags_seq
{
\clist_if_in:nnF { #1 } { ##1 }
{ \seq_map_break:n { \bool_set_false:N \l_karathan_flag_found_bool } }
}
\bool_if:NF \l_karathan_flag_found_bool { \endinput }
}
If all set flags are in the argument of \flags, then the boolean remains true and \endinput is not executed.
Here's a complete example:
\documentclass{article}
\usepackage{xparse,indentfirst}
\ExplSyntaxOn
\NewDocumentCommand{\enableflags}{ m }
{
\karathan_enable_flags:n { #1 }
}
\NewDocumentCommand{\resetflags}{ m }
{
\seq_gclear:N \g_karathan_enabled_flags_seq
\karathan_enable_flags:n { #1 }
}
\NewDocumentCommand{\flags}{ O{} }
{
\karathan_flags:n { #1 }
}
\seq_new:N \g_karathan_enabled_flags_seq
\bool_new:N \l_karathan_flag_found_bool
\cs_new_protected:Npn \karathan_enable_flags:n #1
{
\seq_gset_from_clist:Nn \g_karathan_enabled_flags_seq { #1 }
}
\cs_new_protected:Npn \karathan_flags:n #1
{
\bool_set_true:N \l_karathan_flag_found_bool
\seq_map_inline:Nn \g_karathan_enabled_flags_seq
{
\clist_if_in:nnF { #1 } { ##1 }
{ \seq_map_break:n { \bool_set_false:N \l_karathan_flag_found_bool } }
}
\bool_if:NF \l_karathan_flag_found_bool
%{ \texttt{(#1)}\par }
{ \endinput }
}
\ExplSyntaxOff
\begin{document}
\section{Enabled \texttt{energy}}
\enableflags{energy}
\input{exercise.435.tex}
\input{exercise.436.tex}
\section{Enabled \texttt{entropy}}
\enableflags{entropy}
\input{exercise.435.tex}
\input{exercise.436.tex}
\section{Enabled \texttt{energy}, \texttt{entropy}}
\enableflags{energy,entropy}
\input{exercise.435.tex}
\input{exercise.436.tex}
\section{Enabled \texttt{solid.body}}
\enableflags{solid.body}
\input{exercise.435.tex}
\input{exercise.436.tex}
\section{Enabled \texttt{energy}, \texttt{entropy}, \texttt{solid.body}}
\enableflags{energy, entropy, solid.body}
\input{exercise.435.tex}
\input{exercise.436.tex}
\end{document}

energyandentropythen fileexercise.436isn't displayed that having only flagenergy? – karathan Nov 26 '12 at 06:36