             if let validPath = validPath {
                 temporaryUrl = temporaryUrl.appendingPathComponent(validPath, isDirectory: false)
             }
-            if temporaryUrl.absoluteString.lowercased().prefix(filePrefix.characters.count) != filePrefix {
+            if temporaryUrl.absoluteString.lowercased().prefix(filePrefix.count) != filePrefix {
                 let fixedUrl = filePrefix + temporaryUrl.absoluteString
                 temporaryUrl = URL(string: fixedUrl)!
             }

            .components(separatedBy: invalidCharacters)
            .joined(separator: "")
        let validFileName = removeSlashesAtBeginning(of: pathWithoutIllegalCharacters)
        guard validFileName.characters.count > 0  && validFileName != "." else {
            throw createError(
                .invalidFileName,
                description: "\(originalString) is an invalid file name.",

        let fileExtension = url.pathExtension
        let filePath = url.lastPathComponent
        let fileName = filePath.replacingOccurrences(of: fileExtension, with: "")
        return Int(String(fileName.filter { "0123456789".contains($0) }))
    }
}
