How to convert from DOS path to file scheme URI in Batch file

2k views Asked by At

I'm trying to write a batch file for svnsync, which needs urls to svn repositories. The rest of the batch file uses %~dp0 to get the path of the batch file, but that doesn't work with svnsync.

What is the best way to convert a path (say %~dp0repo, which gets expanded to c:\backup\repo) to a uri suitable for svnsync (file:///c:/backup/repo)?

Ideally it would be able to handle spaces and what not in the path too, so I'd prefer avoid having to use some explicit character replacement to convert from path to URL -- but if that's the only way, oh well.

Thanks!

1

There are 1 answers

7
bobbogo On BEST ANSWER

From your recipe is seems you only need to:

  • Replace \ with /
  • Stick file:/// on the front

Here we go:

set DOSPATH=%~dp0repo
set URI=file:///%DOSPATH:\=/%