How can I create a custom directory (like Table of Contents) e.g. List of Examples?

It's all contained already in tcolorbox with list inside= option and the \tcblistof command.

First define \newtcolorbox[other options,list inside=qex]{...} to generate a new .toc like file with .qex extension (quick examples), then use \tcblistof[\section*]{qex}{Some title}.

\documentclass{article}
\usepackage{fontspec}

\usepackage[most]{tcolorbox}
\usepackage{xparse}
\newcounter{qikexample}


\NewDocumentEnvironment{qikexample}{ O{} } % Optional Title, appears in List of Examples
{
\colorlet{colexam}{gray}
\newtcolorbox[use counter=qikexample,list inside=qex]{qikexamplebox}{%
  % Example Frame Start
    empty,% Empty previously set parameters
    title={Example: #1},% use \thetcbcounter to access the qikexample counter text
    % Attaching a box requires an overlay
    attach boxed title to top left,
    % (boxed title style requires an overlay)
    boxed title style={empty,size=minimal,toprule=0pt,top=4pt,overlay={}},
    coltitle=colexam,fonttitle=\bfseries,
    before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=0pt,right=3mm,top=2pt,breakable,pad at break=0mm,
    before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of parbox=true. This ensures parskip is inherited by box.
    % Handles box when it exists on one page only
    overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: first page
    overlay first={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: middle page
    overlay middle={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: last page
    overlay last={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },%
    }
\begin{qikexamplebox}}
{\end{qikexamplebox}\endlist}

\begin{document}

%\listofexamples
\tcblistof[\section*]{qex}{List of Examples}

\begin{qikexample}[List Contents of Directory in Unix]
ls
\end{qikexample}


\begin{qikexample}[Delete all]
rm *.*
\end{qikexample}
\end{document}

enter image description here


This is code Harish Kumar (who is no user of TeX.SE any longer unfortunately) smuggled into my answer ;-)

tcolorbox provides options with functionality similar to that of xparse provided the library \tcbuselibrary{xparse} is loaded. For example, your box can be generated by

\colorlet{colexam}{gray}
\DeclareTColorBox[use counter=qikexample,list inside=qex]{qikexample}{ O{} }{%
    % Example Frame Start
    empty,% Empty previously set parameters
    title={Example: #1},% use \thetcbcounter to access the qikexample counter text
    % Attaching a box requires an overlay
    attach boxed title to top left,
    % (boxed title style requires an overlay)
    boxed title style={empty,size=minimal,toprule=0pt,top=4pt,overlay={}},
    coltitle=colexam,fonttitle=\bfseries,
    before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=0pt,right=3mm,top=2pt,breakable,pad at break=0mm,
    before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of parbox=true. This ensures parskip is inherited by box.
    % Handles box when it exists on one page only
    overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: first page
    overlay first={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: middle page
    overlay middle={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: last page
    overlay last={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },%
}

I am wondering whether the outer \NewDocumentEnvironment is necessary at all!

New version with some combination of tocloft and tcolorbox features:

The tocloft command \newlistof will automatically define the counter and the \l@.... command as well as the \listof... macro.

Since the tcolorbox uses the qikexample counter, it's necessary to say

\newcommand{\listofexamplesname}{List of Examples}
\newlistof{qikexample}{qex}{\listofexamplesname}

\renewcommand{\cftqikexampledotsep}{\cftnodots}

\NewDocumentCommand{\listofexamples}{}{%
  \listofqikexample
}

Now \listofexamples is a wrapper of \listofqikexample which uses the \l@qikexample entry type.

This has to be specified as list type=qikexample in the tcolorbox options.

Now all \cftX.... macros are available, see the example with \cftqikexampledotsep.

Here is the modified example

\documentclass{article}
\usepackage{fontspec}

\usepackage[most]{tcolorbox}
\usepackage{xparse}
\usepackage{tocloft}

%\newcounter{qikexample}

\newcommand{\listofexamplesname}{List of Examples}
\newlistof{qikexample}{qex}{\listofexamplesname}

\renewcommand{\cftqikexampledotsep}{\cftnodots}

\NewDocumentCommand{\listofexamples}{}{%
  \listofqikexample
}

\NewDocumentEnvironment{qikexample}{ O{} } % Optional Title, appears in List of Examples
{
\colorlet{colexam}{gray}
\newtcolorbox[use counter=qikexample,list inside=qex,list type=qikexample]{qikexamplebox}{%
  % Example Frame Start
    empty,% Empty previously set parameters
    title={Example: #1},% use \thetcbcounter to access the qikexample counter text
    % Attaching a box requires an overlay
    attach boxed title to top left,
    % (boxed title style requires an overlay)
    boxed title style={empty,size=minimal,toprule=0pt,top=4pt,overlay={}},
    coltitle=colexam,fonttitle=\bfseries,
    before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=0pt,right=3mm,top=2pt,breakable,pad at break=0mm,
    before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of parbox=true. This ensures parskip is inherited by box.
    % Handles box when it exists on one page only
    overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: first page
    overlay first={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: middle page
    overlay middle={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: last page
    overlay last={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },%
    }
\begin{qikexamplebox}}
{\end{qikexamplebox}\endlist}

\begin{document}

\listofexamples

\begin{qikexample}[List Contents of Directory in Unix]
ls
\end{qikexample}


\begin{qikexample}[Delete all]
rm *.*
\end{qikexample}
\end{document}

I suggest you use the tocloft package, creating, in the preamble the following:

\newcommand{\listexamplesname}{List of examples}
\newlistof{qikexample}{xmp}{\listexamplesname}

You can, then, in the qikexample environment use \refstepcounter{qikexample} to advance the counter and

    \addcontentsline{xmp}{example}
    {\protect\numberline{\thesection.\theqikexample}#1}\par

to add it to the list. Then in the document \listofqikexamples will print it.

EDIT: I was inspired by this post, and tried to summarize here its content.

Here is a compilable example:

\documentclass{article}
\usepackage{fontspec}
\usepackage{tocloft}
\usepackage{etoolbox}
\usepackage[most]{tcolorbox}
\usepackage{xparse}
% Counters
\newcommand{\listexamplesname}{List of examples}
\newlistof{qikexample}{xmp}{\listexamplesname}
\NewDocumentEnvironment{qikexample}{ O{} } % Optional Title, appears in List of Examples
{
\refstepcounter{qikexample}
\addcontentsline{xmp}{example}
    {\protect\numberline{\thesection.\theqikexample}#1}\par
\colorlet{colexam}{gray}
\newtcolorbox{qikexamplebox}{%
    % Example Frame Start
    empty,% Empty previously set parameters
    title={Example: #1},% use \thetcbcounter to access the qikexample counter text
    % Attaching a box requires an overlay
    attach boxed title to top left,
    % (boxed title style requires an overlay)
    boxed title style={empty,size=minimal,toprule=0pt,top=4pt,overlay={}},
    coltitle=colexam,fonttitle=\bfseries,
 before=\par\medskip\noindent,parbox=false,boxsep=0pt,left=0pt,right=3mm,top=2pt,breakable,pad at break=0mm,
    before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of parbox=true. This ensures parskip is inherited by box.
    % Handles box when it exists on one page only
    overlay unbroken={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: first page
    overlay first={\draw[colexam,line width=.5pt] ([xshift=-10pt]title.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: middle page
    overlay middle={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },
    % Handles multipage box: last page
    overlay last={\draw[colexam,line width=.5pt] ([xshift=-10pt]frame.north west) -- ([xshift=-10pt]frame.south west); },%
    }
\begin{qikexamplebox}}
{\end{qikexamplebox}\endlist}
\begin{document}
\listofqikexample
\begin{qikexample}[List Contents of Directory in Unix]
ls
\end{qikexample}
\end{document}