Esempio n. 1
0
 public static IEnt Find(IDir parent, String rel, bool onlyDir) {
     if (rel.Length == 0 || rel == ".") {
         return parent;
     }
     if (rel.StartsWith("/")) {
         return Find(GetRoot(parent), rel.Substring(1), onlyDir);
     }
     if (rel == "..") {
         return parent.ParentDir;
     }
     if (rel.StartsWith("./")) {
         return Find(parent, rel.Substring(2), onlyDir);
     }
     if (rel.StartsWith("../")) {
         return Find(parent.ParentDir, rel.Substring(3), onlyDir);
     }
     int p = rel.IndexOf('/');
     String part = (p < 0) ? rel : rel.Substring(0, p);
     foreach (IEnt o in parent.GetEnts()) {
         if (o.Name.Equals(part)) {
             if (o is IDir) {
                 if (p < 0)
                     return o;
                 return Find(o as IDir, rel.Substring(p + 1), onlyDir);
             }
             else if (onlyDir) {
                 throw new EntNotFoundException("We knew \"" + rel + "\" is a file.");
             }
             else {
                 if (p < 0)
                     return o;
                 throw new EntNotFoundException("We knew \"" + rel + "\" is a file.");
             }
         }
     }
     throw new EntNotFoundException("We don't find \"" + rel + "\".");
 }