Using Swift 3, I'm writing a video file to the documents folder. here's the path of the file.
file:///var/mobile/Containers/Data/Application/D031AB20-CB7E-4B14-9483-E7C3F4C0EC55/Documents/output11:10:04.mov
now I want to delete the file again using the filemanager
. I retrieve the path above from the avassetwriter
and use the outputurl
I defined earlier to remove the file using the filemanager.
let fileManager = FileManager.default
do {
try fileManager.removeItem(at: (self.assetWriter?.outputURL)!)
} catch let err {
print(err)
}
but I get the error that there is no such file or directory.
using self.assetWriter?.outputURL.path
gives me the same error.
Error Domain=NSCocoaErrorDomain Code=4 "“output11/10/04.mov” couldn’t be removed." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/D031AB20-CB7E-4B14-9483-E7C3F4C0EC55/Documents/output11:10:04.mov, NSUserStringVariant=( Remove ), NSUnderlyingError=0x174240150 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}