Groovy expandUserPath ~


/ Published in: Groovy
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.