import platform
import re


def safe_filename(string):
    """
    Convert a string into one without illegal characters for the given filesystem.

    Args:
        string (str): the path to remove illegal characters from.

    Returns:
        new path string without illegal characters.
    """

    string = string.replace('/', '&').replace('\\', '')

    if platform.system() == "Windows":
        string = re.sub('[":*?<>|]', "", string)

    return string