• 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: length of file from NSFileHandle?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • [SOLVED] Re: length of file from NSFileHandle?
      • From: Graham Cox <email@hidden>
References: 
 >length of file from NSFileHandle? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: length of file from NSFileHandle?
  • Next by Date: Re: Mysterious crash with NSTableView
  • Previous by thread: Re: length of file from NSFileHandle?
  • Next by thread: [SOLVED] Re: length of file from NSFileHandle?
  • Index(es):
    • Date
    • Thread