Exemple #1
0
        public bool Rename([FromBody] DirectoryEntity DirectoryEntity)
        {
            if (!DirectoryEntity.SourcePath.StartsWith("/Files"))
            {
                throw new BadRequestException("Directory path needs start with \"Files\"");
            }
            if (!DirectoryEntity.DestinationPath.StartsWith("/Files"))
            {
                throw new BadRequestException("Directory path needs start with \"Files\"");
            }
            string sourceDirectory      = Path.Combine(Directory.GetCurrentDirectory() + DirectoryEntity.SourcePath);
            string destinationDirectory = Path.Combine(Directory.GetCurrentDirectory() + DirectoryEntity.DestinationPath);

            if (!System.IO.Directory.Exists(sourceDirectory))
            {
                throw new BadRequestException("Source Directory didn't exist");
            }
            if (System.IO.Directory.Exists(destinationDirectory))
            {
                throw new BadRequestException("Destination Directory existed");
            }

            System.IO.Directory.Move(sourceDirectory, destinationDirectory);
            return(true);
        }
Exemple #2
0
        public bool Create([FromBody] DirectoryEntity DirectoryEntity)
        {
            if (!DirectoryEntity.Path.StartsWith("/Files"))
            {
                throw new BadRequestException("Directory path needs start with \"Files\"");
            }
            string folder = Path.Combine(Directory.GetCurrentDirectory() + DirectoryEntity.Path);

            if (System.IO.Directory.Exists(folder))
            {
                throw new BadRequestException("Directory existed");
            }
            else
            {
                System.IO.Directory.CreateDirectory(folder);
            }
            return(true);
        }
Exemple #3
0
        public bool Delete([FromBody] DirectoryEntity DirectoryEntity)
        {
            if (!DirectoryEntity.Path.StartsWith("/Files"))
            {
                throw new BadRequestException("Directory path needs start with \"Files\"");
            }
            string folder = Path.Combine(Directory.GetCurrentDirectory() + DirectoryEntity.Path);

            if (System.IO.Directory.Exists(folder))
            {
                clearFolder(folder);
                if (Directory.GetFiles(folder).Length + Directory.GetDirectories(folder).Length > 0)
                {
                    throw new BadRequestException("Directory didn't empty");
                }
                System.IO.Directory.Delete(folder);
            }
            else
            {
                throw new BadRequestException("Directory didn't existed");
            }
            return(true);
        }