My app has a customized file sort, and I am making an attempt to replace my code in order that once I export or import a file that has a “/” character within the title. At the moment the app simply fails to export a file when it has that character within the title.
That is what I’ve for exporting the file:
static func exportDocument(_ doc: StitchDocument) async -> SentTransferredFile {
log("StitchDocumentWrapper: transferRepresentation: exporting: known as")
let projectURL = doc.getUrl()
// Use the unique doc title (which can comprise "https://stackoverflow.com/") for the exported file
let exportedFileName = doc.title + ".sew"
// Create the momentary export URL within the momentary listing
let tempExportURL = StitchFileManager.tempDir.appendingPathComponent(exportedFileName)
log("StitchDocumentWrapper: transferRepresentation: projectURL: (projectURL)")
log("StitchDocumentWrapper: transferRepresentation: tempExportURL: (tempExportURL)")
do {
// Take away any current file on the temp export URL
attempt? FileManager.default.removeItem(at: tempExportURL)
// Zip current undertaking url's contents to the temp export URL
attempt FileManager.default.zipItem(at: projectURL, to: tempExportURL)
// Return the SentTransferredFile with the temp file URL
return SentTransferredFile(tempExportURL)
} catch {
log("StitchDocumentWrapper: transferRepresentation: FAILED: error: (error)")
// In case of error, nonetheless attempt to return a file, nevertheless it won't comprise the right information
return SentTransferredFile(tempExportURL)
}
}
Word that StitchFileManager
is a sub-class of FileManager
.
The precise drawback is that when the file is exported, it all the time creates extra directories. So, a file named 1/2/3.sew
would create a file on the following listing:
file:///Customers/nicholasarner/Library/Containers/app.stitchdesign.sew/Knowledge/tmp/1/2/3.sew
I would like to determine how protect the file title with out creating extra directories because of the inclusion of the / characters.