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


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


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 Answer

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

This will handle both \ OR / in paths