Working out which OS ColdFusion is running on

We have a mixed development enviroment at the office, some folks on Linux (ubuntu) some on Macs and some on PCs so it is crittical that we make sure that we code properly for all platforms and the one thing that always catches us out is the path seperator.

In the hunt for the perfect solution we knew we had to go to Java to ask it which platform it is running on. A quick search in google finds Luis Majano's post on the subject and this great little code snippet.

<cfscript>
Çspan style='color: #808080'ÈÇemÈ //Get a reference to the System class
Ç/emÈÇ/spanÈobjSystem = createObject("java", "java.lang.System");
Çspan style='color: #808080'ÈÇemÈ //Get the property desired, in this case, the file separator
Ç/emÈÇ/spanÈfileSeparator = objSystem.getProperty("file.separator");
</cfscript>

A nice little thing to add to our application.cfc and cache for later

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)