Search code examples
javascriptinternationalizationfilesystemobject

Create correct path by concatenating LTR with RTL strings


I'm facing a problem in creating correct path by concatenating Arabic folder name with English folder name, the concatenate function seems to work fine if I print the path using document.write(path) which show the correct path but if I pass it to fso.CopyFile(..) I got exception about incorrect path.

function wrap_dir(dir, str) {
if (dir === 'rtl') return '\u202B' + str + '\u202C';
return '\u202A' + str + '\u202C';
}

function Copy(){

var a = 'english'
var b = 'أ.ب-000082-13'
var c = '000004-ر خ-2014.xml'
var strPath = wrap_dir('ltr', '\\\\') + wrap_dir('ltr', a) + wrap_dir('ltr', '\\') + wrap_dir('rtl', b) +    wrap_dir('ltr', '\\') + wrap_dir('ltr', c);
// "‪english‬‪\‬‫أ.ب-000082-13‬‪\‬‪000004-ر خ-2014.xml‬" 

var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile(strPath, to, 1);
}

The strPath variable is "‪\\english‬‪\‬‫أ.ب-000082-13‬‪\‬‪000004-ر خ-2014.xml‬" which is correct path. To make sure that the path is correct I passed that path as a hard code to fso.CopyFile and it worked fine.


Solution

  • You should not insert these RLE(U+202B) LRE(U+202A) PDF(U+202C) control characters.