def download_file_by_name(url, target_folder, file_name, mkdir=False):
<EOL>__hdr__ = {'<STR_LIT>': '<STR_LIT>'<EOL>'<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>'<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:none>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'}<EOL>if not os.path.isdir(target_folder):<EOL><INDENT>if mkdir:<EOL><INDENT>preparedir(target_folder)<EOL><DEDENT>else:<EOL><INDENT>created = preparedir(target_folder, False)<EOL>if not created:<EOL><INDENT>raise ValueError("<STR_LIT>" % target_folder)<EOL><DEDENT><DEDENT><DEDENT>file_path = os.path.join(target_folder, file_name)<EOL>if (sys.version_info < (<NUM_LIT:3>, <NUM_LIT:0>)):<EOL><INDENT>_download_py2(url, file_path, __hdr__)<EOL><DEDENT>else:<EOL><INDENT>_download_py3(url, file_path, __hdr__)<EOL><DEDENT>
Download a file to a directory.

    Args:
        url: A string to a valid URL.
        target_folder: Target folder for download (e.g. c:/ladybug)
        file_name: File name (e.g. testPts.zip).
        mkdir: Set to True to create the directory if doesn't exist (Default: False)