Wednesday, May 29, 2019

Java to get the file separator

There are several different techniques for getting the file separator, i.e. "/" for Linux and "\" for Windows.

In the PSXPFUNCLIB.FUNCLIB.FFo there is a function called GetDirSeparator(), which just looks at the first character of the PS_SERVDIR environment variable. On Linux it will be "/", so it will return this, otherwise if it is not "/" it will return "\".

You can also check the OS environment variable, which on Windows seems to be set to "Windows_NT". So this can be checked and return "\" if it is, otherwise "/".

  • Equally, you could check something like HOME for starting with "/".


Lastly you can also do something like this:
class Utilities;
   property string sDirSeparator get;
   
end-class;

get sDirSeparator
   /+ Returns String +/
   Return GetJavaClass("java.io.File").separator;
end-get;

No comments:

Post a Comment