Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change file extension using swift?

Tags:

ios

swift

I'm using swift code but is not changed file extension.

This my swift code

let url = NSURL(fileURLWithPath: outputURL.path).deletingPathExtension?.appendingPathExtension("mp3")
like image 229
Digvijaysinh Gida Avatar asked Jan 24 '19 07:01

Digvijaysinh Gida


1 Answers

You are just creating a URL and then changing that URL. You are not actually operating on any file.

To rename a file, call FileManager.default.moveItem(at:to:). Pass the file URL as the first argument, and the file URL with the new name as the second argument.

let newURL = outputURL.deletingPathExtension().appendingPathExtension("mp3")
try FileManager.default.moveItem(at: outputURL, to: newURL)
like image 120
Sweeper Avatar answered Sep 29 '22 10:09

Sweeper