-1

I am having a cocoa mac app for OSX.

In my app, I want to get the sizes of all the files in my mac programmatically in objective c.

Here is the image

I have searched a lot but unable to find proper solution.

I am finding the system size with the following code.

NSError *error;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *fileAttributes = [fileManager attributesOfFileSystemForPath:@"/" error:&error];

But how to get the size of all files in mac programmatically.

Please guide me on this.

Thanks in advance.

Please help me.

Manthan
  • 3,856
  • 1
  • 27
  • 58
  • You realize that there is easily a million files on your Mac, and possibly more? – gnasher729 Jul 09 '15 at 13:27
  • I have seen a mac app which finds the size of files having a size above 100Mb. I also want to get the list like that. Is it possible? – Manthan Jul 09 '15 at 13:30

1 Answers1

2

See File Attribute Keys.

NSFileSize

The key in a file attribute dictionary whose value indicates the file's size in bytes.

The corresponding value is an NSNumber object containing an unsigned long long.

unsigned long long fileSize = [fileAttributes[NSFileSize] unsignedLongLongValue];
Droppy
  • 9,691
  • 1
  • 20
  • 27
  • Thanks for your reply again. Can you please give me the exact code for this? I want to get the list of all files with their sizes and paths. – Manthan Jul 09 '15 at 12:13
  • @Manthan Ah you want the size of all files in the filesystem. I cannot be bothered to look at that as it sounds like it will take too long. – Droppy Jul 09 '15 at 12:15
  • I didn't downvote you. – Droppy Jul 09 '15 at 12:19
  • There's no way to ask "please give me a cascading list of every file in the system that I have permission to know about, with their sizes" because (i) basically nobody wants that information; and (ii) that information isn't stored anywhere in that form. Download something like GrandPerspective and check out how long it takes to run if set to scan a whole disk. That's because it has to walk all the folders, querying the information. – Tommy Jul 09 '15 at 12:21
  • Ok buy I don't understand what is wrong in that and people downvote. – Manthan Jul 09 '15 at 12:21
  • @Tommy: Basically I want to get the list of files with sizes above 100 MB. – Manthan Jul 09 '15 at 12:37
  • In that case, read the Spotlight documentation. Don't ask me to do it for you and explain it to you, read it yourself. – gnasher729 Jul 09 '15 at 13:28
  • And if you want a list of all files with sizes above 100 MB, why do you ask a question about getting the sizes of all files, which obviously has a totally different answer? – gnasher729 Jul 09 '15 at 13:30
  • I asked a general question to get the list of files. Yes, that might be not a good one but you should have corrected for that. If you don't want to answer then its also fine. – Manthan Jul 09 '15 at 13:36
  • I got my answer... Thanks @Droppy for your suggetions. http://stackoverflow.com/questions/31308695/get-the-list-of-files-from-selected-folders-having-sizes-100mb-with-their-paths. – Manthan Jul 10 '15 at 12:04