• 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: NSDirectoryEnumerator question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDirectoryEnumerator question


  • Subject: Re: NSDirectoryEnumerator question
  • From: Ricky Sharp <email@hidden>
  • Date: Sat, 10 Feb 2007 10:02:55 -0600

On Feb 10, 2007, at 8:14 AM, Simon Raisin wrote:

I am using NSDirectoryEnumerator to process files and directories. I'd like
to know how I can obtain the file|directory name using the object returned
from [enumerator nextObject].


I can use [enumerator fileAttributes] to get the attributes, but the
file|directory name is not included in that dictionary.

From the docs... "An NSDirectoryEnumerator object enumerates the contents of a directory, returning the pathnames of all files and directories contained within that directory. These pathnames are relative to the directory."


For example:

NSString* theResourcesFolderPath = [[NSBundle mainBundle] resourcePath];
NSDirectoryEnumerator* theResourcesEnumerator = [[NSFileManager defaultManager]
enumeratorAtPath:theResourcesFolderPath];
NSString* theResourcePath = nil;


while ((theResourcePath = [theResourcesEnumerator nextObject]) != nil)
{
NSLog (@"theResourcePath = %@", theResourcePath);
NSLog (@"the file/dir name = %@", [theResourcePath lastPathComponent]);
}


This will log output such as:

theResourcePath = English.lproj
the file/dir name = English.lproj
theResourcePath = English.lproj/AboutScreen.nib
file/dir name = AboutScreen.nib
theResourcePath = English.lproj/AboutScreen.nib/classes.nib
file/dir name = classes.nib
...

If you ever need the full path, that would be a concatenation of the path you fed into enumeratorAtPath: (theResourcesFolderPath) plus the returned path from the enumerator's nextObject:

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >NSDirectoryEnumerator question (From: "Simon Raisin" <email@hidden>)

  • Prev by Date: Re: NSDirectoryEnumerator question
  • Next by Date: Re: Process monitoring
  • Previous by thread: Re: NSDirectoryEnumerator question
  • Next by thread: Register a Drag destination for ANYTHING... mars-alien-spaceship included
  • Index(es):
    • Date
    • Thread