Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the file name from a full path using JavaScript?

Tags:

javascript

Is there a way that I can get the last value (based on the '\' symbol) from a full path?

Example:

C:\Documents and Settings\img\recycled log.jpg

With this case, I just want to get recycled log.jpg from the full path in JavaScript.

like image 975
Jin Yong Avatar asked Jan 08 '09 05:01

Jin Yong


1 Answers

var filename = fullPath.replace(/^.*[\\\/]/, '') 

This will handle both \ OR / in paths

like image 65
nickf Avatar answered Sep 29 '22 00:09

nickf