Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Mac OS X and the invisible attribute
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mac OS X and the invisible attribute



on 3/5/04 11:27 AM, Laurence Harris at email@hidden wrote:

> On 3/5/04 12:03 PM, Eric Arlotti didst favor us with:
>
>> In my Carbon application running on Mac OS X, I try to determine if a
>> file or folder is invisible. When I mean "invisible", I mean : not
>> visible on the Finder or in the Navigation dialogs.
>
> That's the only kind of invisible of which I'm aware.
>>
>> I use FSGetCatalogInfo with the kFSCatInfoFinderInfo flag. My code
>> looks like this :
>>
>> FSCatalogInfo catInfo;
>> Boolean invisible;
>> UInt16 finderFlags;
>>
>> err = FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catalogInfo,
>> NULL, NULL, NULL);
>> if (err == noErr) {
>> finderFlags = ((FileInfo *)&catInfo.finderInfo)->finderFlags;
>> invisible = ((finderFlags & kIsInvisible) != 0) ? true : false;
>> }
>>
>> But it seems I can't rely on FSGetCatalogInfo because ;
>> - for folders or files whose name starts with a dot, the invisible flag
>> is not set although they are not visible on the Finder.
>> - core system files like "mach.sym" or "mac_kernel" don't have the
>> invisible flag set although they are not visible on the Finder.
>> - I have set the invisible attribute using FileBuddy on some files :
>> the invisible flag is set but the files are still visible on the Finder
>> !
>>
>> So, is there a more reliable way to know if a file or folder is
>> invisible ?
>>
> The File Manager is unaware of "Unix invisibility." The files you describe
> are invisible because they are invisible in Unix. To check for that you
> need:
>
> Boolean LSIsInvisible ( const FSRef &inRef )
> {
> LSItemInfoRecord info;
> OSStatus err = LSCopyItemInfoForRef( &inRef,
> kLSRequestBasicFlagsOnly, &info );
>
> return ( err == noErr ? ( kLSItemInfoIsInvisible & info.flags ) != 0 :
> false );
> }

Larry is correct, but there's more.

There are a few ways for things to be considered invisible (under Mac OS X):

- kIsInvisible Finder flag is set
- filename begins with period
- listing in the /.hidden file
- invisible due to parentage
- invisible due to package

What of these matter to you all depends upon your context and situation.

The kIsInvisible flag and the filename starting with a period is your most
typical way for something to be considered invisible (as you defined
"invisible" above). When you check the kLSItemInfoIsInvisible flag, all that
checks for is invisibility due to kIsInvisible and .filename.

There's a hack Apple made called the "/.hidden" file. This is a file named
".hidden" at the root level of your drive. It's just a text file that lists
the various files and folders there at the root level that the OS is to
consider invisible. That's where things like the mach.sym file get their
invisibility from. So if the item is listed in there, treat it as invisible
(and this will spill over into the parentage issue, addressed below). Note
that the /.hidden file is a hack, it can change at any time, Apple could
remove it (I'm to understand they do want to remove it, just a question of
when that will happen), Apple could change the file format.. you never know,
so just be careful with this approach.

An item can also be invisible due to a parent folder being invisible. Let's
say you have:

folder1
folder2
item1

folder2 is invisible by kIsInvisible. Thus, item1 is invisible. item1 itself
may be a visible file (i.e. kIsInvisible is not set, obviously filename
doesn't start with a period), but because folder2 is invisible so are its
contents.

Items within packages... well, this is debatable but given your definition
that invisible means you can't see it in the Finder or Nav Services dialogs,
then it could hold for package contents since you can't see those items in
the Finder or Nav Services dialogs. But of course, you can show package
contents in the Finder and set Nav Services flags to allow navigation into
packages. So this is one of those situations where you have to make the call
based upon whatever it is you're trying to accomplish.

And you thought something as simple as "is this invisible" would be easy to
determine, right? ;-)

--
John C. Daub }:-)>=
<mailto:email@hidden> <http://www.hsoi.com/>
"You really have to be an egomaniac to do this kind of stuff." - Frank
Miller
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Mac OS X and the invisible attribute (From: Laurence Harris <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.