开发者

Remove Trailing Slash From Batch File Input

开发者 https://www.devze.com 2023-01-02 01:53 出处:网络
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 i

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?

:S开发者_运维百科TART
@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


you can use syntax similar your evaluation:

::Does string have a trailing slash? if so remove it 
IF %datapath:~-1%==\ SET datapath=%datapath:~0,-1%
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号