2

I am writing a custom pluggable protocol handler, which is basically the following batch script:

@ECHO off
SET "FullPath=%~1"
explorer.exe "%FullPath%"

However if Windows Explorer passes a UNC with spaces it comes to the script with %20 instead of space:

\Groups\Group%20Micro\

instead of

\Groups\Group Micro\

Can you help me to figure out a batch script snippet replacing "%20" to " " or "\ " in the string please?

So far I found Replace Percent with Bang in String, but it requires somehow to replace % with %%, which is a separate task.

Thank you very much.

Andrey Kazak
  • 41
  • 1
  • 3
  • Answered here: http://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file – markbernard Mar 30 '17 at 17:00
  • Windows Explorer does not URLEncode filenames passed on the command line. How exactly are you getting those filenames? – Ken White Mar 30 '17 at 17:05
  • I open Windows Explorer and enter XXX:\\Groups\Group Micro\ in address input field, then I push Enter and it calls the batch script, where I have XXX:\\Groups\Group%20Micro\ instead of desired XXX:\\Groups\Group Micro\. – Andrey Kazak Mar 30 '17 at 17:08
  • Unfortunately http://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file does not contain a method to replace percent (%) characters in a string. – Andrey Kazak Mar 30 '17 at 17:16
  • Any other ideas? – Andrey Kazak Mar 30 '17 at 17:37
  • Using windows console shell as a CGI, utilizing SED script to URLEncode/Decode. After some time, found this as a easiest and most robust solution. – user2956477 Mar 30 '17 at 18:05

1 Answers1

2

Eventually many thanks to Windows batch script url decoding I worked out desired snippet:

@ECHO off

SET "FullPath=%~1"
REM ECHO %FullPath% & PAUSE

SETLOCAL ENABLEDELAYEDEXPANSION

SET FullPath=%FullPath:smb:=%
SET FullPath=%FullPath:/=\%
SET FullPath=!FullPath:%%20= !

REM ECHO %FullPath% & PAUSE

explorer.exe "%FullPath%"
Community
  • 1
  • 1
Andrey Kazak
  • 41
  • 1
  • 3