Page 1 of 1

How to validate a string is a valid path

Posted: 28 Jan 2020 21:59
by scavenger
Challenge:
- the string path is likely to be on a remote computer (I'm testing backup path returned for some remote SQL servers)
- you cannot try to create the path locally (after all it may be a drive letter not available locally)
- use the minimum lines of code (I can foresee a for loop with : and \ as delimiters)

That's a question... for dummies like me. On Linux it'd be very easy with a simple regex validation.
Have any of you guys done this before?
Would a simple pipe findstr /R do the trick?

thanks

Re: How to validate a string is a valid path

Posted: 28 Jan 2020 22:27
by scavenger
don't bother and archive this.

Code: Select all

echo %REMOTE_PATH% | findstr /I /R "[c-z]:\\[a-z]"
and test ERRORLEVEL, done.