def add2path(folder):
    if not folder:
        return
    import _winreg
    HKCU = _winreg.HKEY_CURRENT_USER
    ENV = "Environment"
    PATH = "PATH"
    DEFAULT = u"%PATH%"

    with _winreg.CreateKey(HKCU, ENV) as key:
        try:
            envpath = _winreg.QueryValueEx(key, PATH)[0]
        except WindowsError:
            envpath = DEFAULT

        paths = [envpath]

        if folder not in envpath:
            if os.path.isdir(folder):
                paths.insert(0, folder)

        envpath = os.pathsep.join(paths)
        _winreg.SetValueEx(key, PATH, 0, _winreg.REG_EXPAND_SZ, envpath)
        _winreg.CloseKey(key)
        notify_win_reg_changes()
        return str(envpath).split(';')
dataset/ETHPy150Open biicode/client/setups/setup_tools.py/add2path/original