Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting number of files in Directory with reference counting

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.

like image 845
Jernej Mihalic Avatar asked Oct 06 '15 21:10

Jernej Mihalic


1 Answers

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...
}
like image 66
user462990 Avatar answered Oct 18 '22 22:10

user462990