How to get the filename from the filepath in swift

后端 未结 10 1511
一生所求
一生所求 2020-12-04 20:47

How to get the filename from the given file path string?

For example if I have a filepath string as

file:///Users/DeveloperTeam/Library/Developer/Co         


        
10条回答
  •  再見小時候
    2020-12-04 21:10

    You can pass the url in fileUrl, like I did below:-

    let fileUrl: String = "https://www.himgs.com/imagenes/hello/social/hello-fb-logo.png" // Pass the URL 
    
    let lastPathComponent = URL.init(string: fileUrl)?.lastPathComponent ?? "" // With this you will get last path component
    
    let fileNameWithExtension = lastPathComponent
    

    //This last path component will provide you file Name with extension.

提交回复
热议问题