Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Convert javascript path to windows path

Explorer ,
Nov 07, 2016 Nov 07, 2016

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

TOPICS
Acrobat SDK and JavaScript , Windows
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2016 Nov 07, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 07, 2016 Nov 07, 2016

I can't run this code:

var dirPathWin = name.replace("/", "\")

It doesnt work...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2016 Nov 07, 2016
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines