Posted By

laurenceosx on 03/28/11


Tagged

groovy


Versions (?)

Groovy expandUserPath ~


 / Published in: Groovy
 

  1. def expandUserPath( aPath ) {
  2. def somethingToDo = aPath.trim().indexOf('~') == 0;
  3. if (!somethingToDo)
  4. return aPath; // !!!!!!!!!!!!!
  5.  
  6. def pathAfterTilde = (aPath.trim() + ' ')[1..-1].trim();
  7.  
  8. def home = System.getProperty('user.home')
  9. def fileSep = System.getProperty( 'file.separator' );
  10.  
  11. def afterTildeIsSlash = pathAfterTilde.startsWith( fileSep )
  12.  
  13. def slash = fileSep
  14. if (afterTildeIsSlash)
  15. slash = ''
  16.  
  17. def result = ( home + slash + pathAfterTilde ).trim();
  18. return result;
  19. }

Report this snippet  

You need to login to post a comment.