iphone - Calculate the size of a folder -
Just a quick one ...
I was making a folder for cache images inside the document My iPhone app I want to be able to keep this folder size up to 1 MB, so I need to check the size in the bytes of my folder.
I have the code to calculate the size of the file, but I need the size of the folder.
What would be the best way to do this? Will I need a loop through each file?
Cheers
Cheers for that Alex, you've helped a lot, Now the following is the task which is written the trick ...
- (unsigned long long int) folder size: (NSString *) folder path {NSArray * filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath: Folder Path Error: zero]; NSEnumerator * filesEnumerator = [FilesArray objectEnumerator]; NSString * fileName; Unsigned long file file size = 0; While {fileName = [FilesEnumerator nextObject]) {NSDictionary * fileDictionary = [[NSFileManager defaultManager] File attributeAppet: [FolderPath stringBeffingPath Company: Filename] Trust link: Yes]; FileSize + = [fileDictionary file size]; } Return file size; }
The explorer does as it comes with the exact number of bytes.
On one side, Finder returns the number two. The size on one disk is the actual number of the second bytes.
For example, when I run this code from my folders, it comes back in code with 'File Size' of 130398. When I check in Finder, then it says that size is 201KB on disk (130,398 bytes).
Whether to go with the actual size here (201 KB or 130,398 bytes) is a little uncertain, for now, I will go to the safe side and cut my threshold to half as long as I I do not know what it means ...
If someone can add more information to these different numbers, then I appreciate it.
Cheers,
Comments
Post a Comment