def CopyFiles(source_dir, target_dir, create_target_dir=False, md5_check=False):
import fnmatch<EOL>if IsDir(source_dir):<EOL><INDENT>source_mask = '<STR_LIT:*>'<EOL><DEDENT>else:<EOL><INDENT>source_dir, source_mask = os.path.split(source_dir)<EOL><DEDENT>if not IsDir(target_dir):<EOL><INDENT>if create_target_dir:<EOL><INDENT>CreateDirectory(target_dir)<EOL><DEDENT>else:<EOL><INDENT>from ._exceptions import DirectoryNotFoundError<EOL>raise DirectoryNotFoundError(target_dir)<EOL><DEDENT><DEDENT>filenames = ListFiles(source_dir)<EOL>if filenames is None:<EOL><INDENT>return<EOL><DEDENT>for i_filename in filenames:<EOL><INDENT>if md5_check and i_filename.endswith('<STR_LIT>'):<EOL><INDENT>continue  <EOL><DEDENT>if fnmatch.fnmatch(i_filename, source_mask):<EOL><INDENT>source_path = source_dir + '<STR_LIT:/>' + i_filename<EOL>target_path = target_dir + '<STR_LIT:/>' + i_filename<EOL>if IsDir(source_path):<EOL><INDENT>CopyFiles(source_path, target_path, create_target_dir=True, md5_check=md5_check)<EOL><DEDENT>else:<EOL><INDENT>CopyFile(source_path, target_path, md5_check=md5_check)<EOL><DEDENT><DEDENT><DEDENT>
Copy files from the given source to the target.

:param unicode source_dir:
    A filename, URL or a file mask.
    Ex.
        x:\coilib50
        x:\coilib50\*
        http://server/directory/file
        ftp://server/directory/file


:param unicode target_dir:
    A directory or an URL
    Ex.
        d:\Temp
        ftp://server/directory

:param bool create_target_dir:
    If True, creates the target path if it doesn't exists.

:param bool md5_check:
    .. seealso:: CopyFile

:raises DirectoryNotFoundError:
    If target_dir does not exist, and create_target_dir is False

.. seealso:: CopyFile for documentation on accepted protocols

.. seealso:: FTP LIMITATIONS at this module's doc for performance issues information