Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Batch: replace %20 to space

Tags:

encoding

space

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.

like image 380
Andrey Kazak Avatar asked Jul 09 '26 23:07

Andrey Kazak


1 Answers

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%"
like image 153
Andrey Kazak Avatar answered Jul 15 '26 07:07

Andrey Kazak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!