001    /**
002     * Implements the Cold Fusion 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                    
014                    int posOfLastDel = path.lastIndexOf('/');
015                    String parent = "";
016                    
017                    if(path.lastIndexOf('\\') > posOfLastDel)
018                            posOfLastDel = path.lastIndexOf("\\");
019                    if(posOfLastDel != -1)
020                            parent = path.substring(0, posOfLastDel + 1);
021                    else
022                    if(path.equals(".") || path.equals(".."))
023                            parent = String.valueOf(File.separatorChar);
024                    else if(path.startsWith("."))
025                            parent = String.valueOf(File.separatorChar);
026                    else
027                            parent = String.valueOf(File.separatorChar);
028                    return parent;
029            }
030    }