I wrote this basename() function for JavaScript today. It parses a file portion for either windows ‘c:pathtofile.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 ];
}
2 Responses
Thank you!
This was very helpful, thanks!
Comments are closed.