Ejemplo n.º 1
0
    public VirtualFolder GetFolder(string path)
    {
        VirtualFolder result = this;

        Trace.Assert(path.StartsWith("/"));

        var parts = path.Split('/');

        for (int i = 1; i < parts.Length; i++)
        {
            string folderName = parts[i];

            if (folderName == "")
            {
                if (i == parts.Length - 1)
                {
                    return(result);
                }
                else
                {
                    Trace.Assert(false, "Empty path name in the middle of path: " + path);
                }
            }

            VirtualEntry entry = result.GetEntry(folderName);
            if (entry == null)
            {
                var new_folder = new VirtualFolder(folderName);
                new_folder.Parent = result;
                result.Entries.Add(new_folder);
                result = new_folder;
            }
            else if (entry.IsDirectory)
            {
                result = (VirtualFolder)entry;
            }
            else
            {
                Trace.Assert(false, "File name in the middle of the path: " + path);
            }
        }


        return(result);
    }