Re: length of file from NSFileHandle?
Re: length of file from NSFileHandle?
- Subject: Re: length of file from NSFileHandle?
- From: Ken Thomases <email@hidden>
- Date: Fri, 26 Aug 2016 22:41:53 -0500
On Aug 26, 2016, at 10:19 PM, Graham Cox <email@hidden> wrote:
>
> Apparently a simple task, but no obvious API for it: getting the length (size) of a file I have a NSFileHandle for. This class has no -length property, so how can I get it?
The reason it has no length property is because not all NSFileHandles have the concept of a length. For example, a file handle associated with a pipe or socket.
For an on-disk file, you can seekToEndOfFile and get offsetInFile to determine the file length. If you need to not perturb the file position, you can record the original offsetInFile and then seekToFileOffset:origOffset to restore it after measuring the length.
Matthew Emerson's suggestion of using fstat() with the fileDescriptor is also reasonable.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden