1

Possible Duplicate:
Linux-style path on windows or vice versa

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?

3
  • 3
    this is a Very Bad Idea
    – unbeli
    Jun 23, 2011 at 22:26
  • 4
    You have a bug - in your requirements. Jun 23, 2011 at 22:27
  • 1
    This is a Very Bad Idea. But, if you must, you could try using UNC. Maybe //?/C:/path/to/file, which (I think) is a valid path in both Windows and Linux).
    – Rob
    Jun 23, 2011 at 22:51

4 Answers 4

1

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.

1

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).

It's a much better idea to follow the conventions of the operating system you're targeting for configuration, logging, etc. Linux has the Linux Standard Base (LSB) and the Filesystem Hierarchy Standard (FHS)

For Windows, there seems to be something similar on MSDN: http://msdn.microsoft.com/en-us/library/cc834998%28v=vs.85%29.aspx

1
  • Yes, that would make sense, but unfortunately in this case, it's not what is wanted.
    – mentics
    Jun 23, 2011 at 23:25
1

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.

0

Well it really depends on the nature of your software. Here are a few suggestions.

  1. Make the path configurable and store in a properties file
  2. Use cygwin and store everything local to the cygwin directory
  3. Use Environment Variables.
  4. Write your own file system.
  5. Send your stakeholder a fish wrapped in a newspaper and politely suggest they reconsider this silly requirement.

I mean thats all I can really think of.

1
  • So far, I have managed to exercise sufficient self control as to avoid #5 which would be my preferred solution.
    – mentics
    Jun 23, 2011 at 23:23

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