I have a folder of images that were imported with Create Folder Reference method, since I want to call images with URLForResoure for transfer to Watch. Before I transfer Images I would like to count them in folder. I was able to get folderURL path with this code:
let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let folderURL = documentsURL.URLByAppendingPathComponent("Folder/SubFolder", isDirectory: true)
but can not get access to files inside this folder.
I want to access files and count them either with same prefix or inside subfolder.
Please help.
Swift3
let fileManager = FileManager.default
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let dirContents = try? fileManager.contentsOfDirectory(atPath: documentsPath)
let count = dirContents?.count
if count == 0{
disableTabBarHistory()// or whatever...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With