Logo
Logo
  • Home
  • Products
  • Writing
  • Work
  • Request Quote
Logo

Backed by 20+ years of hands-on software development expertise, mithra62 transforms ideas into powerful, reliable solutions—designed to work exactly how you want, every time.

  • Address

    Tucson, AZ 85712
  • Email

    eric@mithra62.com
  • Contact

    +1-310-739-3322

Directory separators and cross platform compatibility

  • Home
  • Writing
Directory separators and cross platform compatibility
20 Feb 09
  • Programming
  • Code

I was curious about the impact of the directory separator and how that affects cross platform compatibilitye ver since I started developing on my Vista machine.

I've noticed how different they are compared to the Linux variety. Here's an example:

File path on *nix:

/path/to/file

File path on Windows:

C:\\path\to\file

Dazed and Confused

As you can see the separator is a slash, either a "/" or "" depending on the OS. Why does this matter? Because if we're dealing with files on the server, and the path is going to be recorded so they can be displayed on the Internet, through a URI, than this is going to introduce compatibility issues if not handled correctly. Sigh..

I've seen open source programs handle this type of issue through concatenation. For example the code:

<?php
//$path = 'C:pathtofile.php'; Windows
$path = '/path/to/file.php';
?>

Is written like:

<?php
//$ds = ''; Windows
$ds = '/';
$path = $ ds.'path'.$ds.'$to.'file.php';
?>

Is this even an issue anymore? Both Firefox 2.0 and IE 7 render HTML assets whether the slash is one way or another. Maybe if all paths are written like the *nix variety it's all good...

I did notice that when you have a dual slash Windows chokes:

<?php
$path = '//path/to//dir';
?>

Just something to think about...

UPDATE::
According to the php manual:

On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).

With that in mind it seems kind of dumb to even worry about this anymore. Just use the *nix variety and you should be fine.

Recent Post

  • I'm Speaking! (...again...)
    I’m Speaking! (...again…)
    27 Apr, 2022
  • Guess I Better Start Contributing (...again...)
    Guess I Better Start Contributing (...again…)
    19 Apr, 2022
  • Hello World (... again...)
    Hello World (... again…)
    04 Apr, 2022

follow us

© Copyright 2025 | mithra62

  • Home
  • Products
  • Writing
  • Work
  • Request Quote