I am writing a short batch script which attempts to take the first line of text file and remove the trailing backslash if present. This will then repeat for the remaining lines of the input file. However, when I run the script the line does not remove the backslash. My guess is this is a simple fix, but I have tried several troubleshooting methods with no luck. The code is posted below for reference. Thanks!
@echo on
setLocal EnableDelayedExpansion
::set firstline to firstline of test.txt
set /p firstline=<test.txt
::Remove trailing slash if present
IF !firstline:~-1!==\ SET firstline=!firstline:~0,-1!
::Output firstline (without \ to new txt file)
echo !firstline!>test2.txt
endlocal
test.txt file:
C:\Desktop\example\path\
C:\Desktop\example\path\2\
C:\Desktop\example\path\test\