I building a server that supports file uploading/deleting using Vapor. I am collecting files to be uploaded using something like this:
let path = req.application.directory.workingDirectory
req.fileio.writeFile(.init(data: fileData), at: path)
But I was not sure how to delete those files. I only see options to read/stream/collect/write from the documentation.
Any help would be great!
CodePudding user response:
This is a function I use:
func deleteFile(_ filename: String) throws {
let filepath = try workingDirectoryURL(with: ["folder/of/files", filename]).path
try FileManager.default.removeItem(atPath: filepath)
}
Build the path from the project's base folder.