home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2007 June
/
PCWorld_2007-06_cd.bin
/
multimedia
/
ppsee
/
PPSeeSetup.exe
/
lib
/
bsh-commands-2.0b4.jar
/
bsh
/
commands
/
dirname.bsh
< prev
next >
Wrap
Text File
|
2005-05-23
|
837b
|
32 lines
/**
Return directory portion of path based on the system default file separator.
Note: you should probably use pathToFile() to localize the path relative
to BeanShell's working directory and then file.getAbsolutePath() to get
back to a system localized string.
<p>
Example: to change to the directory that contains the script we're
currently executing:
<pre>
// Change to the directory containing this script
path=pathToFile( getSourceFileInfo() ).getAbsolutePath();
cd( dirname( path ) );
</pre>
*/
bsh.help.cd = "usage: dirname( path )";
String dirname( String pathname )
{
String dirName = ".";
// Normalize '/' to local file separator before work.
int i = pathname.replace('/', File.separatorChar ).lastIndexOf(
File.separator );
if ( i != -1 )
dirName = pathname.substring(0, i);
return dirName;
}