I have a variable, it gets such a record

E:\my\svpo\Settings\

How can I replace reverse single slashes in it with double ones? It should work out like this.

 E:\\my\\svpo\\Settings\\ 

I tried to use ReplaceSubstring but I can’t do anything, I'm noob full in JS. Tell me the solution.

Actually all the code.

 var FSO, WshShell, cur_dir, new_folder, new_file, list, index; // Создаем объект WScript.Shell WshShell = WScript.CreateObject("WScript.Shell"); cur_dir = WshShell.CurrentDirectory; FSO = new ActiveXObject("Scripting.FileSystemObject"); var new_file = FSO.OpenTextFile(""+cur_dir+"\\cur_dir.txt", 2, true); new_file.WriteLine(""+cur_dir+"\\"); WScript.Echo (cur_dir); 
  • With the help of .replace() you can replace \\ with \ - Abmin

1 answer 1

Backslashes are used to escape characters and to denote classes of characters, and must be escaped by themselves both in strings and in regular expressions:

 var str = 'E:\\my\\svpo\\Settings\\'; console.log(str); str = str.replace(/\\/g, '\\\\'); console.log(str); 

The double backslash when writing \\ is actually just a backslash \ , and a quadruple \\\\ is double \\ .

  • This method has already tried, does not work. - Anatoly