Centering a dirtree

It is being centred by \begin{center} but it is always full width so it doesn't actually make any difference. So you need to modify \dirtree not to make a full width box, something like this:

enter image description here

For 2012 version of dirtree you need the following redefinition, for older versions the code in the original answer should work, see %%2012 comments for the differences

\makeatletter
\def\dirtree#1{%
  %%2012\let
  \DT@indent=\parindent
  \parindent=\z@
  %%2012\let
  \DT@parskip=\parskip
  \parskip=\z@
  %%2012\let
  \DT@baselineskip=\baselineskip
  \baselineskip=\DTbaselineskip
  \let\DT@strut=\strut
  \def\strut{\vrule width\z@ height0.7\baselineskip depth0.3\baselineskip}%
  \DT@counti=\z@
  \let\next\DT@readarg
  \next#1\@nil
  \dimen\z@=\hsize
  \advance\dimen\z@ -\DT@offset
  \advance\dimen\z@ -\DT@width
%  \setbox\z@=\hbox to\dimen\z@{%
  \setbox\z@=\hbox{%
%    \hsize=\dimen\z@
    \vbox{\hbox{\@nameuse{DT@body@1}}}%
  }%
  \dimen\z@=\ht\z@
  \advance\dimen0 by\dp\z@
  \advance\dimen0 by-0.7\baselineskip
  \ht\z@=0.7\baselineskip
  \dp\z@=\dimen\z@
  \par\leavevmode
  \kern\DT@offset
  \kern\DT@width
  \box\z@
  \endgraf
  \DT@countii=\@ne
  \DT@countiii=\z@
  \dimen3=\dimen\z@
  \@namedef{DT@lastlevel@1}{-0.7\baselineskip}%
  \loop
  \ifnum\DT@countii<\DT@counti
    \advance\DT@countii \@ne
    \advance\DT@countiii \@ne
    \dimen\z@=\@nameuse{DT@level@\the\DT@countii}\DT@all
    \advance\dimen\z@ by\DT@offset
    \advance\dimen\z@ by-\DT@all
    \leavevmode
    \kern\dimen\z@
    \DT@countiv=\DT@countii
    \count@=\z@
    %%2012\LOOP
    \DT@loop
      \advance\DT@countiv \m@ne
      \ifnum\@nameuse{DT@level@\the\DT@countiv} >
        \@nameuse{DT@level@\the\DT@countii}\relax
      \else
        \count@=\@ne
      \fi
    \ifnum\count@=\z@
    %%2012\REPEAT
    \DT@repeat
    \edef\DT@hsize{\the\hsize}%
    \count@=\@nameuse{DT@level@\the\DT@countii}\relax
    \dimen\z@=\count@\DT@all
    \advance\hsize by-\dimen\z@
    \setbox\z@=\vbox{\hbox{X\@nameuse{DT@body@\the\DT@countii}}}%
    \hsize=\DT@hsize
    \dimen\z@=\ht\z@
    \advance\dimen\z@ by\dp\z@
    \advance\dimen\z@ by-0.7\baselineskip
    \ht\z@=0.7\baselineskip
    \dp\z@=\dimen\z@
    \@nameedef{DT@lastlevel@\the\DT@countii}{\the\dimen3}%
    \advance\dimen3 by\dimen\z@
    \advance\dimen3 by0.7\baselineskip
    \dimen\z@=\@nameuse{DT@lastlevel@\the\DT@countii}\relax
    \advance\dimen\z@ by-\@nameuse{DT@lastlevel@\the\DT@countiv}\relax
    \advance\dimen\z@ by0.3\baselineskip
    \ifnum\@nameuse{DT@level@\the\DT@countiv} <
        \@nameuse{DT@level@\the\DT@countii}\relax
      \advance\dimen\z@ by-0.5\baselineskip
    \fi
    \kern-0.5\DT@rulewidth
    \hbox{\vbox to\z@{\vss\hrule width\DT@rulewidth height\dimen\z@}}%
    \kern-0.5\DT@rulewidth
    \kern-0.5\DT@dotwidth
    \vrule width\DT@dotwidth height0.5\DT@dotwidth depth0.5\DT@dotwidth
    \kern-0.5\DT@dotwidth
    \vrule width\DT@width height0.5\DT@rulewidth depth0.5\DT@rulewidth
    \kern\DT@sep
    \hbox{\box\z@}%
    \endgraf
  \repeat
  \parindent=\DT@indent
  \parskip=\DT@parskip
  %%2012\DT@baselineskip=\baselineskip
  \baselineskip=\DT@baselineskip
  \let\strut\DT@strut
}

\makeatother

Original version:


\documentclass{scrartcl} 
    \usepackage[utf8]{inputenc}
    \usepackage{dirtree,varwidth}

\makeatletter
\def\dirtree#1{%
  \let\DT@indent=\parindent
  \parindent=\z@
  \let\DT@parskip=\parskip
  \parskip=\z@
  \let\DT@baselineskip=\baselineskip
  \baselineskip=\DTbaselineskip
  \let\DT@strut=\strut
  \def\strut{\vrule width\z@ height0.7\baselineskip depth0.3\baselineskip}%
  \DT@counti=\z@
  \let\next\DT@readarg
  \next#1\@nil
  \dimen\z@=\hsize
  \advance\dimen\z@ -\DT@offset
  \advance\dimen\z@ -\DT@width
%  \setbox\z@=\hbox to\dimen\z@{%
  \setbox\z@=\hbox{%
%    \hsize=\dimen\z@
    \vbox{\hbox{\@nameuse{DT@body@1}}}%
  }%
  \dimen\z@=\ht\z@
  \advance\dimen0 by\dp\z@
  \advance\dimen0 by-0.7\baselineskip
  \ht\z@=0.7\baselineskip
  \dp\z@=\dimen\z@
  \par\leavevmode
  \kern\DT@offset
  \kern\DT@width
  \box\z@
  \endgraf
  \DT@countii=\@ne
  \DT@countiii=\z@
  \dimen3=\dimen\z@
  \@namedef{DT@lastlevel@1}{-0.7\baselineskip}%
  \loop
  \ifnum\DT@countii<\DT@counti
    \advance\DT@countii \@ne
    \advance\DT@countiii \@ne
    \dimen\z@=\@nameuse{DT@level@\the\DT@countii}\DT@all
    \advance\dimen\z@ by\DT@offset
    \advance\dimen\z@ by-\DT@all
    \leavevmode
    \kern\dimen\z@
    \DT@countiv=\DT@countii
    \count@=\z@
    \LOOP
      \advance\DT@countiv \m@ne
      \ifnum\@nameuse{DT@level@\the\DT@countiv} >
        \@nameuse{DT@level@\the\DT@countii}\relax
      \else
        \count@=\@ne
      \fi
    \ifnum\count@=\z@
    \REPEAT
    \edef\DT@hsize{\the\hsize}%
    \count@=\@nameuse{DT@level@\the\DT@countii}\relax
    \dimen\z@=\count@\DT@all
    \advance\hsize by-\dimen\z@
    \setbox\z@=\vbox{\hbox{X\@nameuse{DT@body@\the\DT@countii}}}%
    \hsize=\DT@hsize
    \dimen\z@=\ht\z@
    \advance\dimen\z@ by\dp\z@
    \advance\dimen\z@ by-0.7\baselineskip
    \ht\z@=0.7\baselineskip
    \dp\z@=\dimen\z@
    \@nameedef{DT@lastlevel@\the\DT@countii}{\the\dimen3}%
    \advance\dimen3 by\dimen\z@
    \advance\dimen3 by0.7\baselineskip
    \dimen\z@=\@nameuse{DT@lastlevel@\the\DT@countii}\relax
    \advance\dimen\z@ by-\@nameuse{DT@lastlevel@\the\DT@countiv}\relax
    \advance\dimen\z@ by0.3\baselineskip
    \ifnum\@nameuse{DT@level@\the\DT@countiv} <
        \@nameuse{DT@level@\the\DT@countii}\relax
      \advance\dimen\z@ by-0.5\baselineskip
    \fi
    \kern-0.5\DT@rulewidth
    \hbox{\vbox to\z@{\vss\hrule width\DT@rulewidth height\dimen\z@}}%
    \kern-0.5\DT@rulewidth
    \kern-0.5\DT@dotwidth
    \vrule width\DT@dotwidth height0.5\DT@dotwidth depth0.5\DT@dotwidth
    \kern-0.5\DT@dotwidth
    \vrule width\DT@width height0.5\DT@rulewidth depth0.5\DT@rulewidth
    \kern\DT@sep
    \hbox{\box\z@}%
    \endgraf
  \repeat
  \parindent=\DT@indent
  \parskip=\DT@parskip
  \DT@baselineskip=\baselineskip
  \let\strut\DT@strut
}

\makeatother

\begin{document}

\noindent X\dotfill X

\dirtree{%
    .1 sudoku/.
        .2 \_\_init\_\_.py
             \ldots{}
             \begin{minipage}[t]{5cm}
                This directory holds executable files (binary
                files or link on binary files){.}
            \end{minipage}.
        .2 file1.py.
        .2 file2.py.
}

\begin{center}
\begin{varwidth}{\textwidth}
  \dirtree{%
    .1 sudoku/.
        .2 \_\_init\_\_.py
             \ldots{}
             \begin{minipage}[t]{5cm}
                This directory holds executable files (binary
                files or link on binary files){.}
            \end{minipage}.
        .2 file1.py.
        .2 file2.py.
}
\end{varwidth}
\end{center}

\end{document}