Re: Distinguish between Directory and File
Re: Distinguish between Directory and File
- Subject: Re: Distinguish between Directory and File
- From: Gregory Weston <email@hidden>
- Date: Wed, 3 Oct 2007 17:32:27 -0400
Dani wrote:
Hi! I've been trying to write some code to distinguish between a
directory and a file. At first I tried with
fileExistsAtPath:isDirectory method thinking that looking at the
value of isDirectory will told me what I need. I was wrong.
In what way? That routine has never failed me. The only point of
confusion I can imagine is packages that _are_ directories but
_look_like_ files. For that, you can do this:
Boolean theDirectoryFlag = false;
Boolean thePackageFlag = false;
LSItemInfoRecord theItemInfo = {};
if(LSCopyItemInfoForURL(theFileURL, kLSRequestBasicFlagsOnly,
&theItemInfo) == noErr)
{
theDirectoryFlag = (theItemInfo.flags & kLSItemInfoIsContainer) !
= 0;
thePackageFlag = (theItemInfo.flags & kLSItemInfoIsPackage) != 0;
}
Or if you want to stick with Cocoa (that being what this list is
about and all...):
NSWorkspace>>isFilePackageAtPath:
_______________________________________________
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