예제 #1
0
        private void DeleteDirectory(
            FileObject parentDirectory,
            string directoryName,
            FileObject directory,
            DeleteOptions deleteOptions,
            AbsolutePath directoryPath)
        {
            if (!directory.IsDirectory)
            {
                throw new IOException();
            }

            if ((deleteOptions & DeleteOptions.ReadOnly) != 0)
            {
                directory.Attributes &= ~FileAttributes.ReadOnly;
            }

            if ((deleteOptions & DeleteOptions.Recurse) != 0)
            {
                foreach (KeyValuePair <string, FileObject> file in
                         directory.Children.Where(kvp => !kvp.Value.IsDirectory).ToList())
                {
                    if ((deleteOptions & DeleteOptions.ReadOnly) != 0)
                    {
                        file.Value.Attributes &= ~FileAttributes.ReadOnly;
                    }

                    file.Value.DeleteLink(directoryPath / file.Key, true);

                    directory.Children.Remove(file.Key);
                }

                foreach (KeyValuePair <string, FileObject> childDirectory in directory.Children.ToList())
                {
                    DeleteDirectory(
                        directory, childDirectory.Key, childDirectory.Value, deleteOptions, directoryPath / childDirectory.Key);

                    directory.Children.Remove(childDirectory.Key);
                }
            }

            directory.CheckForDelete(null, true);

            parentDirectory.Children.Remove(directoryName);
        }