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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating a string 2

Status
Not open for further replies.

celticking

Technical User
Feb 15, 2001
69
US
Is there a way with Javascript to extract a file name from a path. E.G. c:/myfiles/pics/golf.jpg so i just have golf.jpg? Maybe a strange request but i'd be really thankful for any help.
 
for filenames like that you can use:

fullpath="c:/myfiles/pics/golf.jpg"
filename=fullpath.split("/")[fullpath.split("/").length-1] jaredn@eae.net -
 
myString = new String("c:/myfiles/pics/golf.jpg")
splitString = myString.split("/")
splitString.reverse
picName = splitString[0]

picName now holds "golf.jpg"

hope it helped! :)
Paul Prewett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top