-1

// here frit i want to save a mp4 file before saving i want to check is it alreday there.if there than create another name

let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let  savePathUrl = NSURL(string: ("\(documentsURL.appendingPathComponent("temp"))" + ".mp4"))
if FileManager.default.fileExists(atPath: **savePathUrl**)// here i get error
    }

{
    do

    {
        try FileManager.default.removeItem(atPath: **savePathUrl**)// here i get error
    }
    catch { }

}
Faizul Karim
  • 333
  • 2
  • 13

1 Answers1

1

First off, the way you create savePathUrl makes little sense. Replace:

let  savePathUrl = NSURL(string: ("\(documentsURL.appendingPathComponent("temp"))" + ".mp4"))

with:

let savePathUrl = documentsURL.appendingPathComponent("temp.mp4")

And then for the two FileManager manager methods you need a file path. To get a file path from a file URL, you need to use the path property.

if FileManager.default.fileExists(atPath: savePathUrl.path) {
rmaddy
  • 314,917
  • 42
  • 532
  • 579