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

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.

Best Solution

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

This will handle both \ OR / in paths