1

In a java method i am loading a path name into a string variable, not knowing whether it is a Unix or a Windows path name.

How can i programmatically check whether it is a Unix or a Windows path?

   if path.contains(":") execute a Windows-related function
   else execute a Unix-related function

won't work, because Unix path names can contain a ":" as far as i know. Same with "/" for Unix , because Windows path names can contain a "/" . So how could i do this best?

EDIT: I am loading directory names for remote machines, so i doubt i can use Use System.getProperty("os.name").

i was thinking about using Regex, but since i have no idea about regex in Java i have not considered that yet.

Sandra
  • 103
  • 2
  • 14
  • possible duplicate of [Platform independent paths in Java](http://stackoverflow.com/questions/3548775/platform-independent-paths-in-java) – aarosil Feb 16 '15 at 21:54
  • This sounds like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Why do you need to know whether the path is a Windows or a Linux path? – RealSkeptic Feb 16 '15 at 22:14
  • i need to know it, because i will create a custom xml structure with according tags, depending on whether it is a Windows on a Linux system. – Sandra Feb 16 '15 at 22:20
  • Well, can't the remote machines add that information to the file? – RealSkeptic Feb 16 '15 at 22:33
  • no, the remote machines wont have access to this xml structure – Sandra Feb 17 '15 at 02:05

1 Answers1

0

IMHO, using path names to determine OS platform is not the best idea.

Use System.getProperty("os.name")

and have a look here: How do I programmatically determine operating system in Java?

Community
  • 1
  • 1
Ebeneezer
  • 89
  • 5
  • 3
    The OP was asking how to tell if a given file path was Unix or Windows, not necessarily what platform the program is executing on. – GriffeyDog Feb 16 '15 at 21:58
  • But in fact, the real need, as described by later post of Sandra is: "i will create a custom xml structure with according tags, depending on whether it is a Windows on a Linux system". – Ebeneezer Apr 11 '19 at 10:12