     open func appending(
         path: String,
         relativeTo directory: SearchPathDirectory,
-        options: Options = .none
+        options: CreationOptions = .none
     ) throws -> URL {
-        guard var directoryUrl = url(for: directory) else {
-            throw Error.relativeDirectoryNotFound
+        var directoryUrl = try url(
+            for: directory,
+            in: .userDomainMask,
+            appropriateFor: nil,
+            create: true
+        )
+        .appendingPathComponent(path, isDirectory: true)
+
+        try createDirectory(
+            at: directoryUrl,
+            withIntermediateDirectories: true,
+            attributes: options.attributes
+        )
+
+        if let resourceValue = options.resourceValue {
+            try directoryUrl.setResourceValues(resourceValue)
         }
 
-        directoryUrl = directoryUrl.appendingPathComponent(path, isDirectory: true)
-
-        if case let .createIfNotExists(resourceValue) = options {
-            try createIfNotExists(directoryUrl, resourceValue: resourceValue)
-        }
-
-        if fileExists(atPath: directoryUrl.path) {
-            return directoryUrl
-        }
-
-        throw Error.pathNotFound
+        return directoryUrl
     }
 }
 
 extension FileManager {
-    /// Creates the given url if it does not already exist.
-    open func createIfNotExists(_ url: URL, resourceValue: URLResourceValues? = nil) throws {
-        guard !fileExists(atPath: url.path) else {
-            return
+    /// Removes the file or directory relative to the given directory.
+    open func removeItem(_ path: String, relativeTo directory: SearchPathDirectory, isDirectory: Bool = true) -> Bool {
+        guard var directoryUrl = url(for: directory) else {
+            // No need to remove as it doesn't exists.
+            return true
         }
 
-        guard url.hasDirectoryPath else {
-            throw Error.onlyDirectoryCreationSupported
-        }
+        directoryUrl = directoryUrl.appendingPathComponent(path, isDirectory: isDirectory)
 
-        var url = url
-        try createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
-
-        if let resourceValue = resourceValue {
-            try url.setResourceValues(resourceValue)
+        do {
+            try removeItem(at: directoryUrl)
+            return true
+        } catch {
+            return false
         }
     }
-}
 
-extension FileManager {
+    /// Returns the first URL for the specified common directory in the user domain.
+    open func url(for directory: SearchPathDirectory) -> URL? {
+        urls(for: directory, in: .userDomainMask).first
+    }
+
     /// Remove all cached data from `cachesDirectory`.
     public func removeAllCache() throws {
         try urls(for: .cachesDirectory, in: .userDomainMask).forEach { directory in


extension FileManager {
    var xcoreCacheDirectory: URL? {
        var resourceValue = URLResourceValues()
        resourceValue.isExcludedFromBackup = true

        return try? appending(
            path: "com.xcore",
            relativeTo: .cachesDirectory,
            options: .createIfNotExists(resourceValue)
        )
    }
}

import Foundation

extension FileManager {
    public struct CreationOptions {
        public let resourceValue: URLResourceValues?
        public let attributes: [FileAttributeKey: Any]?

        public init(resourceValue: URLResourceValues?, attributes: [FileAttributeKey: Any]? = nil) {
            self.resourceValue = resourceValue
            self.attributes = attributes
        }

        public static var none: Self {
            .init(resourceValue: nil, attributes: nil)
        }

        /// Excluded from iCloud Backup with `nil` attributes.
        public static var excludedFromBackup: Self {
            // Exclude from iCloud Backup
            var resourceValue = URLResourceValues()
            resourceValue.isExcludedFromBackup = true
            return .init(resourceValue: resourceValue)
        }

        /// Excluded from iCloud Backup with file protection of type `.complete`.
        ///
        /// The file is stored in an encrypted format on disk and cannot be read from or
        /// written to while the device is locked or booting.
        public static var secure: Self {
            // Exclude from iCloud Backup
            var resourceValue = URLResourceValues()
            resourceValue.isExcludedFromBackup = true

            return .init(
                resourceValue: resourceValue,
                attributes: [.protectionKey: FileProtectionType.complete]
            )
        }
    }

    /// Returns a `URL` constructed by appending the given path component relative
