• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: file sizes from NSFileManager
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file sizes from NSFileManager


  • Subject: Re: file sizes from NSFileManager
  • From: Ivan Kourtev <email@hidden>
  • Date: Tue, 7 Oct 2003 23:33:10 -0400

This example from
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/
ObjC_classic/Classes/NSFileManager.html#//apple_ref/doc/uid/20000305/
CHDDEBFF may be helpful.

-- ivan

fileAttributesAtPath:traverseLink:

- ( NSDictionary *) fileAttributesAtPath: (NSString *) path
traverseLink: (BOOL) flag
Returns an NSDictionary containing various objects that represent the
POSIX attributes of the file specified at path . The keys in the
dictionary are described in the Constants section.

If flag is YES and path is a symbolic link, the attributes of the
linked-to file are returned; if the link points to a nonexistent file,
this method returns nil . If flag is NO , the attributes of the
symbolic link are returned.

This piece of code gets several attributes of a file and logs them.
NSNumber *fsize, *refs, *owner;
NSDate *moddate;

NSDictionary *fattrs = [manager fileAttributesAtPath:@"/tmp/List"
traverseLink:YES];

if (!fattrs) {
NSLog(@"Path is incorrect!");
return;
}

if (fsize = [fattrs objectForKey:NSFileSize])
NSLog(@"File size: %d\n", [fsize intValue]);

if (refs = [fattrs objectForKey:NSFileReferenceCount])
NSLog(@"Ref Count: %d\n", [refs intValue]);

if (moddate = [fattrs objectForKey:NSFileModificationDate])
NSLog(@"Modif Date: %@\n", [moddate description]);

As a convenience, NSDictionary provides a set of methods (declared as a
category in NSFileManager.h ) for quickly and efficiently obtaining
attribute information from the returned NSDictionary:
fileGroupOwnerAccountName ,fileModificationDate ,fileOwnerAccountName
,filePosixPermissions ,fileSize ,fileSystemFileNumber ,fileSystemNumber
, and fileType . For example, you could rewrite the last statement in
the code example above as:
if (moddate = [fattrs fileModificationDate])
NSLog(@"Modif Date: %@\n", [moddate description]);

See Also:  changeFileAttributes:atPath:




On Tuesday, Oct 7, 2003, at 23:13 US/Eastern, April Gendill wrote:

> I don't understand how to obtain the file size from NSFileManager. I
> get the dictionary and it has the file size key. The particular folder
> I have been testing with is 12 megs . The dictionary key returns
> 15008530432 which is bytes. Now I must have my math off because I
> thought megs was b / 8 / 1024 /1024.
> The first problem I've has is that when I try to use nsvalue to extract
> an unsigned long long the compiler tells me NSString does not respond
> to unsignedLongLongValue. The only thing other than float, and int that
> I can extract is a double. All of which gives me this number:
> 2123628544 which is so completely not even close to the number returned
> in the dictionary. So.. Since I cannot pass the number in bytes because
> it simply does not work for some reason I cannot fathom, how can I get
> this byte number into a number I can break down to it's kilobyte or
> megabyte size?
>
> Thanks April.
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: file sizes from NSFileManager
      • From: April Gendill <email@hidden>
References: 
 >file sizes from NSFileManager (From: April Gendill <email@hidden>)

  • Prev by Date: file sizes from NSFileManager
  • Next by Date: actions across nibs
  • Previous by thread: file sizes from NSFileManager
  • Next by thread: Re: file sizes from NSFileManager
  • Index(es):
    • Date
    • Thread