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

Re: Path from NSFileHandle?


  • Subject: Re: Path from NSFileHandle?
  • From: Michael Ash <email@hidden>
  • Date: Wed, 8 Apr 2009 23:54:16 -0400

On Wed, Apr 8, 2009 at 11:00 PM, Erg Consultant
<email@hidden> wrote:
> Is there a way to get the path of a file opened by an NSFileHandle from the file handle itself? I have a method that takes only an NSFileHandle to an open file but I don't know the file's path.

Basically, you can't. An NSFileHandle is basically just a wrapper
around a UNIX file descriptor. A file descriptor might not even *have*
a path. For example, it might reference a pipe or network socket. If
it references a file, it might reference a file which has been
deleted. It could also reference a file with multiple hard links,
meaning that it would have *multiple* paths.

It is possible to find this information if you *really* want to. The
fstat() call (use the -fileDescriptor method to get the file
descriptor to pass to it) will give you the device and inode number of
the file, if it has one. You can then search that device for a file
with that inode. But this will be slow, and again it might not even
exist.

Your best bet is to modify your code to pass the path to where it's needed.

Mike
_______________________________________________

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:
    • Re: Path from NSFileHandle?
      • From: "Adam R. Maxwell" <email@hidden>
References: 
 >Path from NSFileHandle? (From: Erg Consultant <email@hidden>)

  • Prev by Date: Re: finder file size
  • Next by Date: Re: finder file size
  • Previous by thread: Path from NSFileHandle?
  • Next by thread: Re: Path from NSFileHandle?
  • Index(es):
    • Date
    • Thread