Remove Trailing Slash From Batch File Input

Posted by Brook on Stack Overflow See other posts from Stack Overflow or by Brook
Published on 2010-06-01T18:49:58Z Indexed on 2010/06/01 18:53 UTC
Read the original article Hit count: 273

Filed under:
|
|
|

I have a batch file that I want to improve. Instead of requiring a user to provide a folder path without a trailing slash, is there an easy way for me to just remove the last character from the path if there is a slash on the end?

:START @echo What folder do you want to process? (Provide a path without a closing backslash) set /p datapath=

::Is string empty? IF X%datapath% == X GOTO:START

::Does string have a trailing slash? IF %datapath:~-1%==\ GOTO:START

© Stack Overflow or respective owner

Related posts about batch

Related posts about batch-file