Search code examples
batch-filebrowserwhitespacelocal-files

Spaces in name of local file are replaced with zeroes when opened in browser


I have a .bat file that opens a local file in a browser. The path to the local file contains spaces (not by my choice):

file:///N:/Users/Firstname%20Lastname/Placeholder%20Report%20Name.html

However, the browser changes this to:

file:///N:/Users/Firstname0Lastname/Placeholder0Report0Name.html

The %20 is replaced with 0 instead of , so the link does not work.

I've tried replacing file:/// with file:\\ and a different browser, but the result is the same. What am I missing? I can't change the name or path of the target file.


Solution

  • You have to escape the % with another one like this:

    file:///N:/Users/Firstname%20Lastname/Placeholder%20Report%20Name.html
    

    ->

    file:///N:/Users/Firstname%%20Lastname/Placeholder%%20Report%%20Name.html
    

    Reason for that is the fact that %2 stands for the second argument, that got send to the batch file:

    yourBat.bat first second
    

    would result in your browser path beeing

    file:///N:/Users/Firstnamesecond0Lastname/Placeholdersecond0Reportsecond0Name.html
    

    as %2 gets substituted with the word second.

    With another % added this will be escaped.