Titus Bui
Titus Bui

Reputation: 75

Handling the window folder path using javascript

I have a window folder path, example:

var text1 = "C:\Mine\2020\example.txt"

But when I print text1 to console, the result: "C:Mine‚0example.txt"

Note: text1 is information from another place. The above case is just an example.

I tried:

String.raw`${text1}`

The result is still: "C:Mine‚0example.txt"

Only when:

String.raw`C:\Mine\2020\example.txt`

The result is exactly what I need: "C:\Mine\2020\example.txt"

But my input is text1 variable. Is there any way to handle the text1 variable? Thanks for any help!

Upvotes: 1

Views: 2261

Answers (3)

Er Pkumar soni
Er Pkumar soni

Reputation: 320

try this

Test code

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

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

result The file was uploaded from: C:\Mine\2020\example.txt

enter link description here

Upvotes: 2

Ehsan Sepehri
Ehsan Sepehri

Reputation: 72

I guess it's useful

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

Upvotes: 1

Ghostile
Ghostile

Reputation: 21

Escape characters my friend.

var text1 = "C:\Mine\2020\example.txt"

Test Code used {

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

}

Result {

 C:\Mine\2020\example.txt

}

If you are unsure about escape characters check the below link. https://www.w3schools.com/js/js_strings.asp

Upvotes: 2

Related Questions