I wrote this basename() function for JavaScript today. It parses a file portion for either windows ‘c:\path\to\file.ext’, *nix ‘/path/to/file.ext’ or href ‘http://server/path/to/file.ext’.
function GetBaseName(file)
{
var Parts = file.split('\\');
if( Parts.length < 2 )
Parts = file.split('/');
return Parts[ Parts.length -1 ];
}



















March 7th, 2008 at 8:53 am
Thank you!
July 19th, 2008 at 2:38 am
This was very helpful, thanks!