Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get filename without extension
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
Copy link

rhcpfan commented Mar 22, 2019

This fails if the filename contains spaces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment