Iterate through files in a folder and its subfolders using Swift’s FileManager
Use the nextObject() method of enumerator: while let element = enumerator?.nextObject() as? String { if element.hasSuffix(“ext”) { // checks the extension } }
Use the nextObject() method of enumerator: while let element = enumerator?.nextObject() as? String { if element.hasSuffix(“ext”) { // checks the extension } }
tl;dr All the other answers are off 🙂 Problem I’d like to add my two cents to this old question as there seem to be many answers that are all very similar but yield results that are in some cases very unprecise. To understand why we first have to define what the size of a … Read more
(The code in this answer has been updated for Swift 3 and later.) Apparently your path variable is a NSURL (describing a file path). To get the path as a string, use the path property, not absoluteString: let exists = FileManager.default.fileExists(atPath: path.path) absoluteString returns the URL in a string format, including the file: scheme etc. … Read more
UPDATE: Since a lot of time has passed after this answer and new methods/APIs have been added, please check the updated answers below for Swift etc; Since I’ve not used them myself, I can’t vouch for them. Original answer: I found the following solution working for me: -(uint64_t)getFreeDiskspace { uint64_t totalSpace = 0; uint64_t totalFreeSpace … Read more