
@echo off
goto start:


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromPath
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%PATH:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set PATH=!tpath!
ENDLOCAL & set PATH=%tpath%
goto :EOF


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromYARP_DATA_DIRSList
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%YARP_DATA_DIRS:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set YARP_DATA_DIRS=!tpath!
ENDLOCAL & set YARP_DATA_DIRS=%tpath%
goto :EOF


@REM code below borrowed from https://stackoverflow.com/a/1430570 (CC-BY-SA 2.5)
@REM Author: Cheeso, Sep 16, 2009

:removeFromXDG_DATA_DIRSList
SETLOCAL ENABLEDELAYEDEXPANSION

@REM  ~fs = remove quotes, full path, short names
set fqElement=%~fs1

@REM convert path to a list of quote-delimited strings, separated by spaces
set fpath="%XDG_DATA_DIRS:;=" "%"

@REM iterate through those path elements
for %%p in (%fpath%) do (
    @REM  ~fs = remove quotes, full path, short names
    set p2=%%~fsp
    @REM is this element NOT the one we want to remove?
    if /i NOT "!p2!"=="%fqElement%" (
        if _!tpath!==_ (set tpath=%%~p) else (set tpath=!tpath!;%%~p)
    )
)

set XDG_DATA_DIRS=!tpath!
ENDLOCAL & set XDG_DATA_DIRS=%tpath%
goto :EOF

:start
if "%COMSPEC%" NEQ "" (
    call :removeFromYARP_DATA_DIRSList "%CONDA_PREFIX%\Library\share\yarp"
    call :removeFromXDG_DATA_DIRSList "%CONDA_PREFIX%\Library\share"
) else (
    call :removeFromYARP_DATA_DIRSList "%CONDA_PREFIX%\share/yarp"
    call :removeFromXDG_DATA_DIRSList "%CONDA_PREFIX%\share"
)
