UNIX中的“ //”问题

$('#lang_choice1').each(function () {
                    var lang = $(this).val();
                    $('#lang_files').empty();
                    $.ajax({
                        type: "POST",
                        url: '<?= site_url('translation/language/getDirContents') ?>',
                        data: {"lang":lang},
                        dataType:"json",
                        success: function (data) {
                            $.each(data,function(id,dir) //here we're doing a foreach loop round each directory with id as the key and directory as the value
                            {
                                var opt = $('<option />'); // here we're creating a new select option with for each directory
                                opt.val(dir);
                                opt.text(dir.substr(dir.lastIndexOf("\\")+1));
                                $('#lang_files').append(opt); //here we will append these new select options to a dropdown with the id
                            });
                            $("#lang_files").val($("#lang_files option:first").val());
                        }

                    });
                    return false;
                });

The usage of opt.text(dir.substr(dir.lastIndexOf("\\")+1));is causing issue in UNIX system.But in windows it works fine. In UNIX it needs to be "/" How can I make it compatible to use in both windows and unix based systems?

I use this style:

$dir = "/root/";   // Root directory to start at

function scanServer($dir){
    global $totalList;
    global $fileList;
    global $dirList;
    global $pathList;

    $files = scandir($dir);               // Obtain all files into an array
    foreach($files as $file){

      if($file != '.' && $file != '..'){
        if(is_dir($dir.'/'.$file)){       // Run self if it is a directory
          $dirList[] = $file;             // Creates a master list of all directories
          scanServer($dir.'/'.$file);
        }else{
          $fileList[] = $file;           // Creates a master list of all files
          $pathList[] = $dir.'/'.$file;  // Creates a master list of absolute paths

        }
      }
    }
  }

foreach($fileList as file){

   echo "<option value='".$file.">".$file."/>";
}