Ejemplo n.º 1
0
        //working for relative and absolute
        public static Response MoveDirectory(string curPath, string newPath)
        {
            var response = ResponseFormation.GetResponse();

            var directory = FileTree.GetDirectory(curPath);

            if (directory == null)
            {
                response.Message = $"Directory {curPath} does not exist";
            }
            else
            {
                DirectoryNode newParent = FileTree.GetDirectory(newPath);
                if (newParent == null)
                {
                    response.Message = $"Directory {newPath} does not exist";
                }
                else
                {
                    DirectoryNode curParent = FileTree.GetDirectory(PathHelpers.GetDirFromPath(curPath));
                    FileTree.RemoveDirectory(curParent, directory);
                    FileTree.AddDirectory(newParent, directory);

                    response.IsSuccess = true;
                    response.Message   = "Directory moved successfully";
                    FileTreeService.UpdateFileTree(FileTree.GetRootDirectory().SerializeToByteArray());
                }
            }

            return(response);
        }
Ejemplo n.º 2
0
        //working for relative and absolute
        public static Response CreateDirectory(string path)
        {
            var response = ResponseFormation.GetResponse();

            var directory = FileTree.GetDirectory(path);

            if (directory != null)
            {
                response.Message = "Directory already exists";
            }
            else
            {
                directory = new DirectoryNode(PathHelpers.GetFilenameFromPath(path));
                var parentDirStr = PathHelpers.GetDirFromPath(path);
                var parent       = FileTree.GetDirectory(parentDirStr);
                if (parent == null)
                {
                    response.Message = $"Directory {parentDirStr} does not exist";
                }
                else
                {
                    FileTree.AddDirectory(parent, directory);
                    response.IsSuccess = true;
                    response.Message   = "Directory created successfully";
                    FileTreeService.UpdateFileTree(FileTree.GetRootDirectory().SerializeToByteArray());
                }
            }

            return(response);
        }