// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // Creation Date: Sept 22, 1999 // // // // // basename(string $path, string $suffix) // // // Strips from $path any prefix ending in '/'. If $path ends in a '/' // it is first stripped. If $suffix is not empty, $suffix will also be // stripped if it exists at the end of $path. On Windows, the input $path is // first processed to convert all backslashes ('\', input as "\\") to '/'s. // // // string $path Path string to strip // string $suffix Suffix to strip off // // // string: the stripped basename // // // string $path = "/usr/people/gamera/gamera.mel"; // string $basename = basename( $path, ".mel" ); // // Result: gamera // // basename( $path, "" ); // // Result: gamera.mel // // string $ntPath = "C:/aw/godzilla/hello.c"; // basename( $ntPath, ".c" ); // // Result: hello // // // // global proc string basename( string $path, string $suffix ) { if ( `about -nt` || `about -mac`) $path = convert( $path ); // Check to make sure we're not chopping off slash if // it's the only path delimiter! if ( (match( "^/$", $path ) == "") && // Root dir (match( "^[A-Za-z]:/$", $path ) == "" ) ) // X:/ on Windows { // Strip off last '/', if it exists $path = substitute("/$", $path, ""); } string $basename; // Is this a UNC path? if ( match( "^//", $path ) != "" ) { // If so, we check if there is anything after the first // component of the path. If not, we return nothing. if ( match( "^//.*/.*", $path ) != "" ) $basename = match( "[^/]*$", $path ); else return ""; } else // We get everything after the last "/" $basename = match("[^/]*$", $path); // if $suffix is given, replace it (if it's at the end) with "" if ( size( $suffix ) != 0 ) { $suffix = $suffix + "$"; $basename = substitute( $suffix, $basename, "" ); } return $basename; }