Q:

How to quickly switch .tex-file by passing arguments to filename?

For example
I have two TeX Projects with a similar filename structure:

The master.tex has a structure like this:
\input{preamble.tex} % <- \bibliography{Projekt_A_Literature} in preamble

% ...

\begin{document}

% ...

    \include{chapter/Projekt_A_cp1.tex}
    \include{chapter/Projket_A_cp2.tex}
    \include{chapter/Projekt_A_cp3.tex}

% ...

\end{document}

the purpose is:  I can easily and quickly change filegroup of chapters to input.
\include{chpater/Project_A_cp1.tex}        \include{chpater/Project_B_cp1.tex}
\include{chpater/Project_A_cp2.tex}  ==>   \include{chpater/Project_B_cp2.tex} 
\include{chapter/Project_A_cp3.tex}        \include{chpater/Project_B_cp3.tex}

a simple but not elegant approach is:
\newcommand{\prjindex}{A} $ or \def\prjindex{A}
%...
\begin{document}
  \include{chpater/Project_\prjindex_cp1.tex}
  \include{chpater/Project_\prjindex_cp2.tex}
  \include{chpater/Project_\prjindex_cp3.tex}    
\end{document}

the question of this solution is, if I compile not in the master TeX file， it gives errors like

Undefined control sequence ....{Project_\prjindex_Literature.tex}.

So I came here for a more elegant solution

A:

Seems you need a "mechanism" for autodetecting \prjindex in situations where a definition of \prjindex is not provided "by hand".

Preliminary remarks:
Usually the expansion of the primitive \jobname forms the name of that file (without extension) which was used for initiating compilation.
E.g., if you compile a project whose main file is testfile.tex via the commandline
latex testfile.tex
, the primitive \jobname will expand to the phrase testfile.
Character-tokens in phrases delivered by \jobname will always be of category code 12(other) while spaces will always be of category code 10(space).
The phrase testfile that comes from expanding \jobname will be used for 

creating the .log-file: The .log-file will be named testfile.log.
creating the main .aux-file: That will be named testfile.aux.
creating the .toc-file holding data for the table of contents: That will be named testfile.toc.
creating the .lof-file holding data for the list of figures: That will be named testfile.lof.
creating the .lot-file holding data for the list of tables: That will be named testfile.lot.
etc.

But with most nowadays TeX distributions you can have (La)TeX deviate from the usual way of handling things:
With most nowadays TeX distributions you can at the commandline provide a commandline-option (the ‑‑jobname-option) which lets you change what phrase \jobname will deliver.
E.g., if you compile a project whose main file is testfile.tex via the commandline
latex --jobname=foobar testfile.tex
, the primitive \jobname will expand to the phrase foobar.  
In this case the phrase foobar that comes from expanding \jobname will be used for 

creating the .log-file: The .log-file will be named foobar.log.
creating the main .aux-file: That will be named foobar.aux.
creating the .toc-file holding data for the table of contents: That will be named foobar.toc.
creating the .lof-file holding data for the list of figures: That will be named foobar.lof.
creating the .lot-file holding data for the list of tables: That will be named foobar.lot.
etc.

With my suggestion below it is a requrement that LaTeX handles things in the usual way, i.e., things are to be compiled without providing some ‑‑jobname-option.
Therefore my suggestion below is not be suitable for people who use such (online-)LaTeX-platforms/TeX-editors/user-interfaces where under the hood things are configured to make use of the ‑‑jobname-option.

In case the names of all those files during whose compilation the definition of \prjindex is to be "autodetected" (as it will not be defined "by hand") are of pattern Projekt_&langle#1&rangle_&langle#2&rangle.tex— &langle#1&rangle both denoting the project and not being empty and not containing underscores (_)—, andcalling latex for "standalone compiling" files during whose compilation the definition of \prjindex is to be "autodetected" always takes place without invoking the ‑‑jobname-option (which implies that the expansion of the \jobname-primitive forms the name of that file (without extension) which was used for initiating compilation), I can offer a macro \GetPrjindexFromJobnameIfUndefined which acts as follows:
In case the macro \prjindex is already defined, it does nothing.
In case the macro \prjindex is not defined, it checks whether the expansion of the \jobname-primitive is of pattern Projekt_&langle#1&rangle_&langle#2&rangle. If it is not of that pattern, an error-message will be triggerd. If it is of that pattern, it will be examined whether &langle#1&rangle will be empty. If this is the case, an error-message will be triggered. If this is not the case, the macro \prjindex will be defined to expand to &langle#1&rangle.
I cannot make a decision whether that routine is of use to you because you did not reveal in all too much detail how that part of the file-structure of your project is organized which makes it possible to compile the single Projekt_&langle#1&rangle_&langle#2&rangle.tex-files both "standalone" and when invoked from a master tex-file via \input or \include.
In case all project-files somehow share the same preamble, you can probably make this routine available to all project-files via that preamble.
Probably you can include that routine (and the call to it) into your preamble.tex. That routine does nothing in case \prjindex is already defined.
Thereforewithin master.tex you can define \prjindex before inputting preamble.tex.the scenario of standalone-compiling one of your Projekt_&langle#1&rangle_&langle#2&rangle.tex-files leads to inputting \preamble.tex while \prjindex is not yet defined, which in turn leads to the routine \GetPrjindexFromJobnameIfUndefined "autodetecting" and defining \prjindex for you by examining the result of the expansion of \jobname. 
\documentclass{article}

%%========Code for \GetPrjindexFromJobnameIfUndefined=========
\begingroup
\makeatletter
\def\prjprephrase{Projekt_}%
\def\prjpostphrase{_}%
% \jobname delivers everything but the space (which will be of catcode 10) 
% with catcode 12(other). Therefore "sanitizing" is needed for turning
% everything but the space into catcode 12(other):
\@onelevel@sanitize\prjprephrase
\@onelevel@sanitize\prjpostphrase
\newcommand\GetPrjindexFromJobnameIfUndefined[2]{%
  \endgroup
  \newcommand\GetPrjindexFromJobnameIfUndefined{%
    \@ifundefined{prjindex}{%
      \expandafter\GetPrjindexCheckPattern\jobname$#1#2$&%
    }{}%
  }%
  \@ifdefinable\GetPrjindexCheckPattern{%
    \def\GetPrjindexCheckPattern##1#1##2#2##3$##4&{%
      \GetPrjindexPatternfork
      &##4&{\expandafter\GetPrjindexExtractfrompattern\jobname$}%
      &#1#2$&{%
        \GenericError{(\string\prjindex)\space}{%
          Error on input line \the \inputlineno:\MessageBreak
          \string\GetPrjindexFromJobnameIfUndefined\space cannot extract the\MessageBreak
          \string\prjindex\space from \string\jobname's expansion.\MessageBreak
          (\string\GetPrjindexFromJobnameIfUndefined\space is defined\MessageBreak
           \space somewhere in this document.)\@gobble
        }{Have a look at the comments in this document.}%
        {%
          \string\GetPrjindexFromJobnameIfUndefined\space can extract the \string\prjindex\MessageBreak
          from \string\jobname's expansion only in case \string\jobname's expansion is\MessageBreak
          of pattern\MessageBreak
          \@spaces #1\string####1#2\string####2\MessageBreak
          while \string####1 is not empty.\MessageBreak
          If this is the case, the expansion of \string\prjindex\space will be \string####1.\MessageBreak
          \string####1 will not contain underscores (\string_).\MessageBreak
          \string####2 can contain underscores.\MessageBreak
        }%
      }%
      &&&&%
    }%
  }%
  \@ifdefinable\GetPrjindexPatternfork{%
    \def\GetPrjindexPatternfork##1&#1#2$&##2##3&&&&{##2}%
  }%
  \@ifdefinable\GetPrjindexExtractfrompattern{%
    \def\GetPrjindexExtractfrompattern#1##1#2##2${%
      \ifx\relax##1\relax
        \expandafter\@firstoftwo
      \else
        \expandafter\@secondoftwo
      \fi
      {%
        \GenericError{(\string\prjindex)\space}{%
          Error on input line \the \inputlineno:\MessageBreak
          \string\prjindex\space is empty.\MessageBreak
          (\string\GetPrjindexFromJobnameIfUndefined\space is defined\MessageBreak
           \space somewhere in this document.)\@gobble
        }{Have a look at the comments in this document.}%
        {%
          \string\GetPrjindexFromJobnameIfUndefined\space can extract the \string\prjindex\MessageBreak
          from \string\jobname's expansion only in case \string\jobname's expansion is\MessageBreak
          of pattern\MessageBreak
          \@spaces #1\string####1#2\string####2\MessageBreak
          while \string####1 is not empty.\MessageBreak
          If this is the case, the expansion of \string\prjindex\space will be \string####1.\MessageBreak
          \string####1 will not contain underscores (\string_).\MessageBreak
          \string####2 can contain underscores.\MessageBreak
        }%
      }%
      {\newcommand*\prjindex{##1}}%
    }%
  }%
}%
\expandafter\expandafter\expandafter\GetPrjindexFromJobnameIfUndefined
\expandafter\expandafter\expandafter{\expandafter\prjprephrase\expandafter}%
\expandafter{\prjpostphrase}%
%%=====End of code for \GetPrjindexFromJobnameIfUndefined=====

\GetPrjindexFromJobnameIfUndefined

\show\prjindex

\begin{document}
Some document
\end{document}

By the way: For testing the routine I saved the example above as test.tex and compiled it, invoking the ‑‑jobname-option with different values.
Compiling via the command latex test.tex yielded as expected:
! Error on input line 80:
(\prjindex) \GetPrjindexFromJobnameIfUndefined cannot extract the
(\prjindex) \prjindex from \jobname's expansion.
(\prjindex) (\GetPrjindexFromJobnameIfUndefined is defined
(\prjindex)  somewhere in this document.)

Have a look at the comments in this document.
Type  H <return>  for immediate help.
 ...                                              

l.80 \GetPrjindexFromJobnameIfUndefined

? 
> \prjindex=undefined.
l.82 \show\prjindex

This was expected as in this case \jobname expanded to test which is not of pattern
Projekt_&langle#1&rangle_&langle#2&rangle.
Compiling via the command latex ‑‑jobname=Projekt_A_4  test.tex yielded as expected:
\prjindex=macro:
->A.
l.82 \show\prjindex

(You would get the same when the example was saved as Projekt_A_4.tex and compiled via the command latex Projekt_A_4.tex.)
Compiling via the command latex ‑‑jobname=Projekt_B_4 test.tex yielded as expected:
\prjindex=macro:
->B.
l.82 \show\prjindex

(You would get the same when the example was saved as Projekt_B_4.tex and compiled via the command latex Projekt_B_4.tex.)
Compiling via the command latex ‑‑jobname=Projekt_JohannGambolputty_12345 test.tex yielded as expected:
\prjindex=macro:
->JohannGambolputty.
l.82 \show\prjindex

(You would get the same when the example was saved as Projekt_JohannGambolputty_12345.tex and compiled via the command latex Projekt_JohannGambolputty_12345.tex.)
By the way:
Sometimes I organize my project-files as follows:
Preamble.tex
% Check whether the \documentclass-command was already invoked.
% If so, increment \inputlevel and stop inputting.
% If not so, don't stop imputting and thus do all the
% preamble-stuff, inclusive defining \inputlevel:
\expandafter\ifx\csname @twoclasseserror\endcsname\documentclass
  \xdef\inputlevel{\number\numexpr\inputlevel+1\relax}%
  \expandafter\endinput
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
\documentclass{article}%
% 
\newcommand*\inputlevel{1}%
\global\let\inputlevel=\inputlevel
%
% Whatsoever preamble-commands, etc.
%
% Here you can also place the code for defining \GetPrjindexFromJobnameIfUndefined
% and then invoke it for defining \prjindex:
%
%%========Code for \GetPrjindexFromJobnameIfUndefined=========
\begingroup
\makeatletter
\def\prjprephrase{Projekt_}%
\def\prjpostphrase{_}%
% \jobname delivers everything but the space (which will be of catcode 10) 
% with catcode 12(other). Therefore "sanitizing" is needed for turning
% everything but the space into catcode 12(other):
\@onelevel@sanitize\prjprephrase
\@onelevel@sanitize\prjpostphrase
\newcommand\GetPrjindexFromJobnameIfUndefined[2]{%
  \endgroup
  \newcommand\GetPrjindexFromJobnameIfUndefined{%
    \@ifundefined{prjindex}{%
      \expandafter\GetPrjindexCheckPattern\jobname$#1#2$&%
    }{}%
  }%
  \@ifdefinable\GetPrjindexCheckPattern{%
    \def\GetPrjindexCheckPattern##1#1##2#2##3$##4&{%
      \GetPrjindexPatternfork
      &##4&{\expandafter\GetPrjindexExtractfrompattern\jobname$}%
      &#1#2$&{%
        \GenericError{(\string\prjindex)\space}{%
          Error on input line \the \inputlineno:\MessageBreak
          \string\GetPrjindexFromJobnameIfUndefined\space cannot extract the\MessageBreak
          \string\prjindex\space from \string\jobname's expansion.\MessageBreak
          (\string\GetPrjindexFromJobnameIfUndefined\space is defined\MessageBreak
           \space somewhere in this document.)\@gobble
        }{Have a look at the comments in this document.}%
        {%
          \string\GetPrjindexFromJobnameIfUndefined\space can extract the \string\prjindex\MessageBreak
          from \string\jobname's expansion only in case \string\jobname's expansion is\MessageBreak
          of pattern\MessageBreak
          \@spaces #1\string####1#2\string####2\MessageBreak
          while \string####1 is not empty.\MessageBreak
          If this is the case, the expansion of \string\prjindex\space will be \string####1.\MessageBreak
          \string####1 will not contain underscores (\string_).\MessageBreak
          \string####2 can contain underscores.\MessageBreak
        }%
      }%
      &&&&%
    }%
  }%
  \@ifdefinable\GetPrjindexPatternfork{%
    \def\GetPrjindexPatternfork##1&#1#2$&##2##3&&&&{##2}%
  }%
  \@ifdefinable\GetPrjindexExtractfrompattern{%
    \def\GetPrjindexExtractfrompattern#1##1#2##2${%
      \ifx\relax##1\relax
        \expandafter\@firstoftwo
      \else
        \expandafter\@secondoftwo
      \fi
      {%
        \GenericError{(\string\prjindex)\space}{%
          Error on input line \the \inputlineno:\MessageBreak
          \string\prjindex\space is empty.\MessageBreak
          (\string\GetPrjindexFromJobnameIfUndefined\space is defined\MessageBreak
           \space somewhere in this document.)\@gobble
        }{Have a look at the comments in this document.}%
        {%
          \string\GetPrjindexFromJobnameIfUndefined\space can extract the \string\prjindex\MessageBreak
          from \string\jobname's expansion only in case \string\jobname's expansion is\MessageBreak
          of pattern\MessageBreak
          \@spaces #1\string####1#2\string####2\MessageBreak
          while \string####1 is not empty.\MessageBreak
          If this is the case, the expansion of \string\prjindex\space will be \string####1.\MessageBreak
          \string####1 will not contain underscores (\string_).\MessageBreak
          \string####2 can contain underscores.\MessageBreak
        }%
      }%
      {\newcommand*\prjindex{##1}}%
    }%
  }%
}%
\expandafter\expandafter\expandafter\GetPrjindexFromJobnameIfUndefined
\expandafter\expandafter\expandafter{\expandafter\prjprephrase\expandafter}%
\expandafter{\prjpostphrase}%
%%=====End of code for \GetPrjindexFromJobnameIfUndefined=====
% 
% This will define \prjindex depending on the expansion of \jobname
% while \jobname usually represents the name of the file used for
% initiating compilation:
%
% !!! I don't know whether, e.g., online-latex-plattforms like overleaf
% !!! invoke latex using the -jobname-option, which would lead to
% !!! the expansion of \jobname deviating from the name of the file
% !!! used for initiating compilation.
%
\GetPrjindexFromJobnameIfUndefined
%
% With subsequent preamble-commands you can, if you wish, fork depending on
% the expansion of \prjindex. But be aware that like \jobname \prjindex also
% holds only characters of catcode 12(other) and spaces of catcode 10(space).
% Therefore when storing a string in a temporary macro (this should, like
% \prjindex not be defined in terms of \long, which is the case with
% \def or \newcommand*) and \ifx-comparing that temporary macro to \prjindex,
% make sure that the definition of that temporary macro is "sanitized" by
% means of \@onelevel@sanitize before doing the \ifx-comparison.
%
%  \usepackage...
%  \usepackage...
%
\begin{document}%
\endinput
|
| Place whatsoever comments remarks and explanations and manuals you wish to place 
| here. They won't be processed because LaTeX ceases reading and processing this
| file when encountering \endinput.

Postamble.tex
\csname @\ifnum\inputlevel>1 second\else first\fi oftwo\endcsname
{%
  \end{document}%
}{%
  \xdef\inputlevel{\number\numexpr\inputlevel-1\relax}%
}%

Projekt_A_cp1.tex
%----------------------
\input{Preamble.tex}%
%----------------------
This is file \texttt{Projekt\string_A\string_cp1.tex}\par
This is the text in file \texttt{Projekt\string_\prjindex\string_cp1.tex}.\par
The file \texttt{Projekt\string_\prjindex\string_cp1.tex} invokes the file \texttt{Projekt\string_\prjindex\string_cp2.tex}:\par
\input{Projekt_\prjindex_cp2.tex}%
%----------------------
\input{Postamble.tex}%
%----------------------

Projekt_A_cp2.tex
%----------------------
\input{Preamble.tex}%
%----------------------
This is file \texttt{Projekt\string_A\string_cp2.tex}\par
This is the text in file \texttt{Projekt\string_\prjindex\string_cp2.tex}.\par
The file \texttt{Projekt\string_\prjindex\string_cp2.tex} invokes the file \texttt{Projekt\string_\prjindex\string_cp3.tex}:\par
\input{Projekt_\prjindex_cp3.tex}%
%----------------------
\input{Postamble.tex}%
%----------------------

Projekt_A_cp3.tex
%----------------------
\input{Preamble.tex}%
%----------------------
This is file \texttt{Projekt\string_A\string_cp3.tex}\par
This is the text in file \texttt{Projekt\string_\prjindex\string_cp3.tex}.\par
%----------------------
\input{Postamble.tex}%
%----------------------

Projekt_B_cp1.tex
%----------------------
\input{Preamble.tex}%
%----------------------
This is file \texttt{Projekt\string_B\string_cp1.tex}\par
This is the text in file \texttt{Projekt\string_\prjindex\string_cp1.tex}.\par
The file \texttt{Projekt\string_\prjindex\string_cp1.tex} invokes the file \texttt{Projekt\string_\prjindex\string_cp2.tex}:\par
\input{Projekt_\prjindex_cp2.tex}%
%----------------------
\input{Postamble.tex}%
%----------------------

Projekt_B_cp2.tex
%----------------------
\input{Preamble.tex}%
%----------------------
This is file \texttt{Projekt\string_B\string_cp2.tex}\par
This is the text in file \texttt{Projekt\string_\prjindex\string_cp2.tex}.\par
The file \texttt{Projekt\string_\prjindex\string_cp2.tex} invokes the file \texttt{Projekt\string_\prjindex\string_cp3.tex}:\par
\input{Projekt_\prjindex_cp3.tex}%
%----------------------
\input{Postamble.tex}%
%----------------------

Projekt_B_cp3.tex
%----------------------
\input{Preamble.tex}%
%----------------------
This is file \texttt{Projekt\string_B\string_cp3.tex}\par
This is the text in file \texttt{Projekt\string_\prjindex\string_cp3.tex}.\par
%----------------------
\input{Postamble.tex}%
%----------------------

This way each of the files Projekt_A_cp1.tex, Projekt_A_cp2.tex, Projekt_A_cp3.tex
respective each of the files Projekt_B_cp1.tex, Projekt_B_cp2.tex, Projekt_B_cp3.tex
can be used both for compiling "standalone" and for being invoked via \input or via \include by another file of the same project.
Preamble.tex can contain code where forking takes place depending on the
meaning of \prjindex, so things can be handled differently for different
projects within the same preamble-file.

