001 /** 002 * Implements the CFML Function getdirectoryfrompath 003 */ 004 package railo.runtime.functions.system; 005 006 import java.io.File; 007 008 import railo.runtime.PageContext; 009 import railo.runtime.ext.function.Function; 010 011 public final class GetDirectoryFromPath implements Function { 012 public static String call(PageContext pc , String path) { 013 return invoke(path); 014 } 015 016 public static String invoke(String path) { 017 int posOfLastDel = path.lastIndexOf('/'); 018 String parent = ""; 019 020 if(path.lastIndexOf('\\') > posOfLastDel) 021 posOfLastDel = path.lastIndexOf("\\"); 022 if(posOfLastDel != -1) 023 parent = path.substring(0, posOfLastDel + 1); 024 else 025 if(path.equals(".") || path.equals("..")) 026 parent = String.valueOf(File.separatorChar); 027 else if(path.startsWith(".")) 028 parent = String.valueOf(File.separatorChar); 029 else 030 parent = String.valueOf(File.separatorChar); 031 return parent; 032 } 033 }