使用 javascript 处理 window 文件夹路径

Handling the window folder path using javascript

我有一个window文件夹路径,例如:

var text1 = "C:\Mine20\example.txt"

但是当我打印 text1 到控制台时,结果:"C:Mine‚0example.txt"

注:text1是别处的信息。以上案例只是一个例子。

我试过了:

String.raw`${text1}`

结果仍然是:"C:Mine‚0example.txt"

仅当:

String.raw`C:\Mine20\example.txt`

结果正是我需要的:"C:\Mine20\example.txt"

但我的输入是 text1 变量。有什么办法可以处理 text1 变量吗?感谢您的帮助!

转义字符我的朋友。

var text1 = "C:\Mine20\example.txt"

使用测试代码 {

var text1 = "C:\Mine\2020\example.txt";
alert(text1);

}

结果 {

 C:\Mine20\example.txt

}

如果您不确定转义字符,请检查下面的 link。 https://www.w3schools.com/js/js_strings.asp

我觉得有用

var text1 = "C:\Mine\2020\example.txt"
console.log(text1)

try this

测试代码

const filePath = String.raw `C:\Mine20\example.txt`;

console.log(The file was uploaded from: ${filePath});

结果 文件上传自:C:\Mine20\example.txt

enter link description here