def check_filename ( filename ) : if not isinstance ( filename , str ) : raise TypeError ( "filename must be a string" ) if regex . path . linux . filename . search ( filename ) : return True return False
how to check whether a filename contains certain characters in python
Returns a boolean stating if the filename is safe to use or not . Note that this does not test for legal names accepted but a more restricted set of : Letters numbers spaces hyphens underscores and periods .
def check_filename(filename):
    """
    Returns a boolean stating if the filename is safe to use or not. Note that
    this does not test for "legal" names accepted, but a more restricted set of:
    Letters, numbers, spaces, hyphens, underscores and periods.

    :param filename: name of a file as a string
    :return: boolean if it is a safe file name
    """
    if not isinstance(filename, str):
        raise TypeError("filename must be a string")
    if regex.path.linux.filename.search(filename):
        return True
    return False