1

I have a local directory and want to share a clickable link that will open the user's default file browser.

How to generate an URL of the file:// protocol for a given local filename?

some_program /foo/bar    # file:///foo/bar
some_program "/föö bar"    # file:///f%C3%B6%C3%B6%20bar
some_program "$( realpath . )"    # link to local directory

I found some hints for the reverse operation utilizing naive replacement commands in sed what fails for filenames with non-alphanumeric characters like whitespace.

1 Answer 1

1

The Perl module URI::file supports this:

$ perl -MURI::file -E'say URI::file->new($_) for @ARGV' /foo/bar
file:///foo/bar

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .