Get filename without extension

Posted by

Consider the following filename:


We are interested in getting filename only (without extension). We can do so with the help of following code:

let path = "hls_a128_v4.m3u8"
let url = URL(string: path)
let filename = url?.deletingPathExtension().lastPathComponent
print(filename) // hls_a128_v4
let fileExtension = url?.pathExtension
print(fileExtension) // m3u8


  1. I do consider all the ideas you’ve presented to your post. They’re really convincing and can definitely work. Nonetheless, the posts are too brief for newbies. Could you please prolong them a little from next time? Thank you for the post.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s