home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 25 / FreelogHS25.iso / Dessin / ArtOfIllusion2.2.1 / ArtOfIllusion.jar / bsh / commands / dirname.bsh < prev    next >
Text File  |  2005-05-23  |  837b  |  32 lines

  1. /**
  2.     Return directory portion of path based on the system default file separator.
  3.     Note: you should probably use pathToFile() to localize the path relative
  4.     to BeanShell's working directory and then file.getAbsolutePath() to get
  5.     back to a system localized string.
  6.     <p>
  7.     
  8.     Example: to change to the directory that contains the script we're 
  9.     currently executing:
  10.  
  11.     <pre>
  12.     // Change to the directory containing this script
  13.     path=pathToFile( getSourceFileInfo() ).getAbsolutePath();
  14.     cd( dirname( path ) );
  15.     </pre>
  16. */
  17.  
  18. bsh.help.cd = "usage: dirname( path )";
  19.  
  20. String dirname( String pathname ) 
  21. {
  22.     String dirName = ".";
  23.     // Normalize '/' to local file separator before work.
  24.     int i = pathname.replace('/', File.separatorChar ).lastIndexOf( 
  25.         File.separator );
  26.     if ( i != -1 )
  27.         dirName = pathname.substring(0, i);
  28.  
  29.     return dirName;
  30. }
  31.  
  32.