I have set up the following code to save a file to the documents directory:
NSLog(@\"Saving File...\");
NSURLRequest *request = [NSURLRequest requestWithURL
Function that returns array of URLs of all files in Documents directory that are MP4 videos. If you want all files, just remove the filter.
It checks only files in the top directory. If you want to list also files in the subdirectories, remove the .skipsSubdirectoryDescendants option.
func listVideos() -> [URL] {
let fileManager = FileManager.default
let documentDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
let files = try? fileManager.contentsOfDirectory(
at: documentDirectory,
includingPropertiesForKeys: nil,
options: [.skipsSubdirectoryDescendants, .skipsHiddenFiles]
).filter {
$0.lastPathComponent.hasSuffix(".mp4")
}
return files ?? []
}