Columbus, Ohio

basename() function for JavaScript

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

Comments are closed.

Join My FREE Newsletter

Get the latest news and episodes of the Cloud Entrepreneur Podcast and Angelo’s development blog directly in your inbox!