Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backslash problem on Mac

Status
Not open for further replies.

juanferman

Programmer
Nov 14, 2001
40
0
0
US
Hey Guys,

I'm having a hard time trying to get the file name from a Mac Path like C:\\foo\folder\dork.txt

I have a file upload button that onchange event takes the path and extracts the file name. Then it puts the file name in a free text filed in order to allow the user to tell what file name he wants before upload the file or if he wants just to leave the original name.

Sounds easy, actually works pretty good on PC but when trying to implement it on Mac does not work.

On PC I'm getting the value of the file upload button and splitting the path by "/". But on Mac the path has already a "\".

Any help will be really appreciate.

Thanks



===================
::) Juan F. Sarria
 
Maybe try replacing all \ with / before doing the split?
Code:
str = "C:\\foo\folder\dork.txt";
str = str.replace(/\\/g, "/");
str = str.split("/");

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Yea, I tried that before the posting.

Once you declare the variable

str = "C:\\foo\folder\dork.txt";

the "\" is escaping the string "\\", "\f" and "\d"

Just try

str = "C:\\foo\folder\dork.txt";
alert(str)

and you will see what I'm talking about.

Thanks


===================
::) Juan F. Sarria
 
Hmm... good question. Wish I had a mac to work out the solution on. Any chance you're extracting the location server side? Then you could pad the string with backslashes before the variable is defined.

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top