Can Chrome open a local file with relative path set via link?

8,564

Solution 1

.LNK is a shortcut file, not an NTFS soft symbolic link. The former can contain an editable Target field where you can add parameters, not the latter.

You can try creating a shortcut to portable_chrome.exe and in the Target field add index.html to it, so that it looks like "Drive:\Path\to\portable_chrome.exe" index.html. While shortcuts cannot contain relative paths, launching them will cause them to auto-resolve so in this case whatever be the path portable_chrome.exe should be located and used since it exists in the same directory as the shortcut itself.

Alternately, you can create a one-liner Launch.bat batch file in the same directory with portable_chrome.exe index.html in it.

Solution 2

Just in case (since it's an old question) :

It is not possible to use relative paths, however you can write a batch file and use : %~dp0 to get the current directory. (more here : SO question)

Then, you can launch whatever file you want in your drive with :

portable_chrome.exe file:///%~dp0path-to-your-file/index.html

Share:
8,564

Related videos on Youtube

fma
Author by

fma

Updated on September 18, 2022

Comments

  • fma
    fma almost 2 years

    Lets say the following windows file-structure is given:

    ./
    ./portable_chrome.exe
    ./index.html
    ./load_index.lnk
    

    Is there a way to open the index.html with portable_chrome.exe via load_index.lnk with relative adressing? (not via file:///)

    Thanks for an answer!

  • Karan
    Karan over 11 years
    I think you missed the point of the question completely. The OP's not asking about the file path/URI displayed in the browser's address bar.
  • fma
    fma over 11 years
    Thanks, I wrote a script, I was just curious whether its possible or not
  • Synetech
    Synetech over 11 years
    While shortcuts cannot contain relative paths… They cannot contain relative paths for the program (what exactly would they be relative to anyway, the location of the shortcut file? the current directory when it is launched?), however they can indeed have relative paths for command-line arguments because Explorer does not parse arguments and therefore does not distinguish parameters that are paths. It simply appends arguments to the command in the shortcut as-is. It is the program that parses them, converting any relative paths relative to the location specified in the Start In field.
  • Karan
    Karan over 11 years
    @Synetech: I guess I thought it was obvious I was referring to relative paths for the very thing the shortcut is pointing to, but maybe I wasn't clear enough. Of course you can tag on anything as an argument, even a relative path, and it's the program's responsibility to deal with it. (Also, I'd love to create relative shortcuts, especially on removable read-only media that ends up with different drive letters every time.)
  • Synetech
    Synetech over 11 years
    I was referring to relative paths for the very thing the shortcut is pointing to But the question is asking about relative paths for the arguments. I'd love to create relative shortcuts, especially on removable read-only media that ends up with different drive letters every time. Indeed. Unfortunately the closest we can get is to use a batch file (making sure to use start so that the console is closed after launching the program).
  • Karan
    Karan over 11 years
    @Synetech: "But the question is asking about relative paths for the arguments." As I mentioned above "Drive:\Path\to\portable_chrome.exe" index.html will work and one need not even specify a path to the HTML file as long as it resides in the same dir as the portable Chrome EXE (which it does as per the question). However due to the limitations of shortcuts a batch file is the best solution, and I think we agree on that point.
  • Synetech
    Synetech over 11 years
    as long as it resides in the same dir as the portable Chrome EXE (which it does as per the question) I think that was just an example, hence the “let’s say”. The annoying thing is that even the latest version of Windows doesn’t improve the .lnk format (though it has changed a bit over the years since the first one, just not enough). :-|