diff options
Diffstat (limited to 'Hotline/Shared/URLAdditions.swift')
| -rw-r--r-- | Hotline/Shared/URLAdditions.swift | 26 |
1 files changed, 0 insertions, 26 deletions
diff --git a/Hotline/Shared/URLAdditions.swift b/Hotline/Shared/URLAdditions.swift deleted file mode 100644 index 1f25541..0000000 --- a/Hotline/Shared/URLAdditions.swift +++ /dev/null @@ -1,26 +0,0 @@ -import Foundation - -extension URL { - func generateUniqueFilePath(filename base: String) -> String { - let fileManager = FileManager.default - var finalName = base - var counter = 2 - - // Helper function to generate a new filename with a counter - func makeFileName() -> String { - let baseName = (base as NSString).deletingPathExtension - let extensionName = (base as NSString).pathExtension - return extensionName.isEmpty ? "\(baseName) \(counter)" : "\(baseName) \(counter).\(extensionName)" - } - - // Check if file exists and append counter until a unique name is found - var filePath = self.appending(component: finalName).path(percentEncoded: false) - while fileManager.fileExists(atPath: filePath) { - finalName = makeFileName() - filePath = self.appending(component: finalName).path(percentEncoded: false) - counter += 1 - } - - return filePath - } -} |