Batch function for removing trailing backslashes -


i want function remove last slash/slashes, write code multiple times:

if %variable:~-1%==\ set variable=%variable:~0,-1% 

so i'll have smth this

set var1=c:\folder\ call :removetrailingbackslash var1 

echo %var1% - should see "c:\folder" here

@echo off setlocal set var1=c:\somewhere\\\\\\\\\\\\ call :removetrailingbackslash var1 echo var1=%var1% goto :eof :removetrailingbackslash if not defined %1 goto :eof setlocal call set $_=%%%1%% if %$_:~-1%==\ endlocal&call set "%1=%%%1:~0,-1%%"&goto removetrailingbackslash goto :eof 

this procedure should remove trailing backslashes. how works, i'll leave exercise reader :)


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -