Copy link to clipboard
Copied
I have a string that contains a path that is formatted like this:
/C/Users/heresh/Desktop/output/2016
How can I convert this path to a windows path:
C:\Users\heresh\Desktop\output\2016
I know I should use:
path.replace() but I cant get it to work
Copy link to clipboard
Copied
It's a simple string manipulation.
- Replace all slashes with back-slashes.
- Remove the first back-slash.
- Replace the first back-slash with a colon followed by a back-slash.
You can read about the various String methods in JS here: JavaScript String Reference
Copy link to clipboard
Copied
I can't run this code:
var dirPathWin = name.replace("/", "\")
It doesnt work...
Copy link to clipboard
Copied
A back-slash is a special character that needs to be escaped, so the correct code to use is:
name.replace("/", "\\");
However, this will only replace the first forward-slash in the string. To replace all of them you should use a Regular Expression, not just a string.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now