Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting just the filename from a path with JavaScript

I have a full path to an image, which I am using jQuery to read like this:

$('img.my_image').attr('src'); 

However I just want the filename portion (i.e. without full path).

Are there any built-in functions to do this, or would a regex be the only option?

like image 342
DCD Avatar asked Mar 26 '10 19:03

DCD


People also ask

How do I find the filename of a path?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

Which function is used to retrieve the filename from the given path?

GetFileName(String) Returns the file name and extension of the specified path string.

What is the file name in a URL?

The filename is the last part of the URL from the last trailing slash. For example, if the URL is http://www.example.com/dir/file.html then file. html is the file name.


1 Answers

var Filename= path.split('/').pop() 
like image 187
rash Avatar answered Sep 18 '22 09:09

rash