Re: NSDirectoryEnumerator question
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