NOTE: I should have included this in advance. I am very aware this is a very bad idea, that it makes little sense, etc. But sometimes, there are situations outside of our control that drive us to find solutions that make no sense.

We have a requirement for a property file to be placed on both windows and linux without changes and it contains absolute paths. I know that basic "/some/path" works on both, but on Windows, that's a path based on the current drive letter.

Is there some way to specify a path in such a way that it could go across drive letters on Windows?

In other words, if "/D:/some/path" worked on windows (which it doesn't) that path could be created on Linux. Is there something like that that could work?

4 Answers
4

This really will not work. If you want an absolute path in Windows, it will require the drive letter. Linux doesn't use letters, it just uses mounts on "/". A relative path from the app folder is a much better idea.

Why not have separate property files for each target OS? I assume you have to package your application differently (MSI vs RPM or similar), so what's the harm in separate files (which could be generated from a single "base" file to avoid getting out of sync with each other).

If possible, allow the paths in the file to be relative, e.g. to the program's installation directory or a similar directory. Alternatively, if it is your own code that is reading this file, you could allow environment variables in the paths, e.g. $INSTALL_DIR/lib/foo. Your program could then arrange to set $INSTALL_DIR to the appropriate directory before reading this file, or it could simply be a magic token which is replaced with the install directory and not a real environment variable.