Ejemplo n.º 1
0
        /// <markdown>
        /// ### public void DirectoryCopy(string path, string name)
        /// </markdown>
        /// <summary>
        /// Copies a directory at the path specified with the new name at the same level
        /// </summary>
        /// <param name="path">The path of the directory to rename</param>
        /// <param name="name">The new name of the directory</param>
        /// <returns>The renamed directory view</returns>
        public DirectoryInfoView DirectoryCopy(string path, string name)
        {
            string fullPath = FullRoot + path;

            //throw directory doesn't exist method
            if (!Directory.Exists(fullPath))
            {
                throw new DirectoryNotFoundException("Directory '" + path + "' does not exist");
            }
            //get new path
            DirectoryInfo diP     = new DirectoryInfo(fullPath);
            string        newPath = diP.Parent.FullName + @"\" + name;

            //throw exception if move directory exists
            if (Directory.Exists(newPath))
            {
                throw new Exception("Directory '" + path + "' already exists");
            }

            // Copy from the current directory, include subdirectories.
            DirectoryCopy(fullPath, newPath, true);

            DirectoryInfo     di  = new DirectoryInfo(newPath);
            DirectoryInfoView div = CreateDirectoryInfoView(di);

            //return model
            return(CleanDirectoryView(div));
        }
Ejemplo n.º 2
0
        /// <markdown>
        /// ### public DirectoryInfoView GetDirectoryInfoView(string relativePath = "", bool populateChildren = true, bool recursive = true)
        /// </markdown>
        /// <summary>
        /// Returns a DirectoryInfoView for the relative path from the root, with optionally appended children and recursive children
        /// </summary>
        /// <param name="relativePath">Optional relative path from root</param>
        /// <param name="populateChildren">Set to true to populate child directories and files, defaults to true</param>
        /// <param name="recursive">Set to true to recursively construct all child directories</param>
        /// <returns>The matching directory info view</returns>
        public DirectoryInfoView GetDirectoryInfoView(string relativePath = "", bool populateChildren = true, bool recursive = true)
        {
            //rebuild reltative path
            relativePath = RebuildRelativePath(relativePath);
            string fullPath = FullRoot + relativePath + @"\";
            string path     = Root + relativePath;

            //throw directory doesn't exist method
            if (!Directory.Exists(fullPath))
            {
                throw new DirectoryNotFoundException("Directory '" + path + "' does not exist");
            }
            DirectoryInfo     di  = new DirectoryInfo(fullPath);
            DirectoryInfoView div = CreateDirectoryInfoView(di);

            //populate children if requested
            if (populateChildren)
            {
                //add child files
                foreach (var file in di.GetFiles())
                {
                    div.ChildFiles.Add(CreateFileInfoView(file));
                }
                //get child directories
                DirectoryInfo[] childDirectories = di.GetDirectories();
                foreach (var i in childDirectories)
                {
                    //if recursive then get child directories
                    if (recursive)
                    {
                        string rp = relativePath + @"\" + i.Name;
                        div.ChildDirectories.Add(GetDirectoryInfoView(rp, populateChildren, recursive));
                    }
                    else
                    {
                        DirectoryInfoView div2 = CreateDirectoryInfoView(i);
                        div2 = CleanDirectoryView(div2);
                        div.ChildDirectories.Add(div2);
                    }
                }
            }
            //clean children
            foreach (var c in div.ChildFiles)
            {
                CleanFileView(c);
            }
            //clean directory view
            div = CleanDirectoryView(div);
            return(div);
        }
Ejemplo n.º 3
0
        /// <markdown>
        /// ### public void DirectoryCreate(string path)
        /// </markdown>
        /// <summary>
        /// Creates a new directory at the path specified
        /// </summary>
        /// <param name="path">The path of the directory to create</param>
        /// <returns>The newly created directory view</returns>
        public DirectoryInfoView DirectoryCreate(string path, bool throwOnExist = true)
        {
            string fullPath = FullRoot + path;

            //throw directory exist method
            if (Directory.Exists(fullPath))
            {
                if (throwOnExist)
                {
                    throw new Exception("Directory '" + path + "' already exists");
                }
            }
            else
            {
                Directory.CreateDirectory(fullPath);
            }
            DirectoryInfo     di  = new DirectoryInfo(fullPath);
            DirectoryInfoView div = CreateDirectoryInfoView(di);

            //return model
            return(CleanDirectoryView(div));
        }
Ejemplo n.º 4
0
 /// <markdown>
 /// ### public FileInfoView CleanDirectoryView(FileInfoView directory)
 /// </markdown>
 /// <summary>
 /// Cleans a resource directory full paths and leaving it with relative paths only
 /// </summary>
 /// <param name="directory">The directory to clean</param>
 /// <returns>The cleaned directory</returns>
 public DirectoryInfoView CleanDirectoryView(DirectoryInfoView directory)
 {
     directory.FullName = directory.FullName.Replace(FullRoot, "");
     return(directory);
 }