Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

how to get the path of selected PDF/doc from file manager in ios swift programmatically

// Get the document directory url
let documentsUrl =  FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

do {
    // Get the directory contents urls (including subfolders urls)
    let directoryContents = try FileManager.default.contentsOfDirectory(at: documentsUrl, includingPropertiesForKeys: nil)
    print(directoryContents)

    // if you want to filter the directory contents you can do like this:
    let mp3Files = directoryContents.filter{ $0.pathExtension == "mp3" }
    print("mp3 urls:",mp3Files)
    let mp3FileNames = mp3Files.map{ $0.deletingPathExtension().lastPathComponent }
    print("mp3 list:", mp3FileNames)

} catch {
    print(error)
}
Comment

PREVIOUS NEXT
Code Example
Swift :: button click programmatically swift 
Swift :: swift dictionary sorted 
Swift :: guard let swift 
Swift :: UIFont.init bold 
Swift :: Nested if...else Statement 
Swift :: deselect all cell in collectionview 
Swift :: Swift Character Example 
Swift :: debounce in swift 
Swift :: make text autoresize swiftui 
Swift :: Swift guard-let Statement 
Swift :: swift lazy 
Swift :: Convert JSON to Data 
Swift :: Swift Access Array Elements 
Swift :: Swift Static Properties 
Swift :: swiftui tap gesture 
Swift :: how to screen record swift stackoverflow 
Swift :: To get IPAddress for wifi , wired, and cellular 
Swift :: swift output 
Swift :: swift looping through array 
Swift :: array of button listeners swift 
Swift :: code that detect input swift 
Swift :: Notification Service Extension vs Content Extension 
Swift :: swift isMemberOf 
Swift :: swift get all cases starting with 
Swift :: enum Associated Values Swift 
Swift :: swift get last element of array 
Ruby :: activerecord list tables 
Ruby :: ruby memory location 
Ruby :: activerecord less than 
Ruby :: rails change date format 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =