This is a variation of this question: Remove Trailing Slash From Batch File Input
but it's subtly different, so I don't think it's a dupe.
I'm having trouble making this work with directories that have spaces in them (running WinXP).
: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 so remove it
IF %datapath:~-1%==\ SET datapath=%datapath:~0,-1%
echo %datapath%
It handles:
c:\
properly (stripping it to c:)
But if you enter:
c:\test space
the error is "space was unexpected at this time."
If you try enter:
"c:\test space"
You get the same error.
I thought it would involve a strategically placed " or two in this line:
IF %datapath:~-1%==\ SET datapath=%datapath:~0,-1%
But I haven't had any luck.
Any ideas?