Ejemplo n.º 1
0
    public Dir FindOrCreate(string path, bool mightBeFile = true)
    {
        int i = path.IndexOf('/');

        if (i > -1)
        {
            Dir dir = FindOrCreate(path.Substring(0, i), false);
            return(dir.FindOrCreate(path.Substring(i + 1), true));
        }
        // if the name is at the end of a path and contains a "."
        // we assume it is a file (unless it is "." by itself)
        if (mightBeFile && path != "." && path.Contains("."))
        {
            Files.Add(path);
            return(this);
        }
        Dir child;

        if (Dirs.ContainsKey(path))
        {
            child = Dirs[path];
        }
        else
        {
            child = new Dir(path);
            Dirs.Add(path, child);
        }
        return(child);
    }
    public Dir FindOrCreate(string path)
    {
        int i = path.IndexOf('/');

        if (i > -1)
        {
            Dir dir = FindOrCreate(path.Substring(0, i));
            return(dir.FindOrCreate(path.Substring(i + 1)));
        }
        // if the path contains a "." it is a file, unless it is "." by itself
        if (path != "." && path.Contains("."))
        {
            Files.Add(path);
            return(this);
        }
        Dir child;

        if (Dirs.ContainsKey(path))
        {
            child = Dirs[path];
        }
        else
        {
            child = new Dir(path);
            Dirs.Add(path, child);
        }
        return(child);
    }
Ejemplo n.º 3
0
        public Dir FindOrCreate(string path, string fullPath, bool mightBeFile = true)
        {
            int i = path.IndexOf('\\');

            if (i > -1)
            {
                Dir      dir  = FindOrCreate(path.Substring(0, i), fullPath, false);
                FileInfo info = new FileInfo(fullPath);
                dir.DateCreated = info.CreationTime.ToString("dddd, dd MMMM yyyy");
                return(dir.FindOrCreate(path.Substring(i + 1), fullPath, true));
            }

            if (path == "")
            {
                return(this);
            }

            if (mightBeFile && path != "." && path.Contains("."))
            {
                FileInfo info = new FileInfo(fullPath);
                Files.Add(new File(path, info.Length.ToString() + " B", fullPath));
                return(this);
            }

            Dir child;

            if (Dirs.ContainsKey(path))
            {
                child = Dirs[path];
            }
            else
            {
                child = new Dir(path);
                FileInfo info = new FileInfo(fullPath);
                child.DateCreated = info.CreationTime.ToString("dddd, dd MMMM yyyy");
                Dirs.Add(path, child);
            }
            return(child);
        }