Aquí hay otro método que funciona si su desea eliminar el% cd% desde el inicio de una cadena. Es lento, pero puede reducir el número de bucles si la situación lo permite.
call :removeCommonAtStart outvar C:\Users\Public\Documents\ASUSAccess
:removeCommonAtStart
:: Description: loops through two strings and sets new variable representing unique data
:: Required parameters:
:: name - name of the variable to be returned
:: test - string to have common data removed from start
:: Optional parameters:
:: remove - string if not defined then use %cd% as string.
:: Required functions:
:: removelet
set name=%~1
set test=%~2
set remove=%~3
if not defined remove set remove=%cd%
set endmatch=
FOR /L %%l IN (0,1,150) DO if not defined notequal call :removelet
goto :eof
:removelet
:: Description: called by removeCommonAtStart to remove one letter from the start of two string variables
:: Required preset variables:
:: test
:: remove
:: name
set test=%test:~1%
set %name%=%test:~1%
set remove=%remove:~1%
if "%test:~0,1%" neq "%remove:~0,1%" set notequal=on&exit /b
goto :eof
¡Gracias, eso parece funcionar perfectamente! Nunca antes había visto esa sintaxis, ¿podría proporcionar una explicación o un enlace? –
También estoy votando porque funciona, aunque odio decirlo, no sé por qué. –
Escriba: 'SET /?' Y busque la explicación en "La sustitución de variable de entorno se ha mejorado de la siguiente manera:% PATH: str1 = str2%" y también en: "Expansión de variable de entorno retrasada le permite ..." – Aacini