chuck clark wrote:
Hi,
I would like to enter a folder path like this
C:\Documents and Settings\chucklarge\Desktop
and get this
C:\\Documents and Settings\\chucklarge\\Desktop\\
this is what i have tried but can not get it right
function preparePath(folderPath)
{ var len = folderPath.length;
if(folderPath[len - 1] != '\\')
{ folderPath += '\\';
}
return folderPath.replace(\\, '\\\');
}
sourceFolderPath = preparePath("C:\Documents and
Settings\chucklarge\Desktop");
Any Help is appreciated,
Chuck
Here ya go... I think you are getting confused about escape characters.
Whenever you have a string with a \, there needs to be another
character, so "\\\\" evaluates to \\. In your function, you are
replacing \\ with "\\\" which is guaranteed to break, since you are
escaping the second double-quote, and the string never closes.
Also, in your test, you need to add \\ in the path, because it will be
evaluated as \ before you send it into the function. _THIS IS
DIFFERENT_ from if you are handed a string with a \ in it. The escape
character \ is only used by the inputting user.
Brian
function preparePath(folderPath)
{
if(folderPath[folderPath.length - 1] != "\\")
folderPath += "\\";
return folderPath.replace(/\\/g, "\\\\");
}
sourceFolderPath = preparePath("C:\\Documents and
Settings\\chucklarge\\Desktop");