Skip navigation.
 
mltesting for invisible files in a file browser
FROM : Tyler Riddle
DATE : Wed Aug 09 01:17:42 2006

Howdy all,

I searched the archives and found some example code that does is
supposed to return a BOOL regarding the invisibleness of a file in the
filesystem. I wrote a small wrapper around it to test invisibleness
from the command line but it does not work as expected. For instance,
when pointed at /etc (which is invisible to the finder on my machine),
the returned value indicates the folder is visible. I'm at a loss as
to why the code does not work. Can anyone provide some insight?

Thanks in advance,

Tyler Riddle

compile with "gcc -framework Foundation -framework CoreServices
hidden.m -o hidden"

BEGIN hidden.m
#import <Foundation/Foundation.h>

#import <stdio.h>

BOOL isVisible(NSString *path) {
   if ([[path lastPathComponent] hasPrefix:@"."]) {
       return NO;
   }

   FSRef possibleInvisibleFile;
   FSCatalogInfo catalogInfo;
   OSStatus errStat = FSPathMakeRef([path fileSystemRepresentation],
&possibleInvisibleFile, NULL);

   if (errStat < 0) {
       printf("FSPathMakeRef() error %i\n", errStat);
       return NO;
   }

   errStat = FSGetCatalogInfo(&possibleInvisibleFile,
kFSCatInfoFinderInfo, &catalogInfo, nil, nil, nil);

   if (errStat < 0) {
       printf("FSGetCatalogInfo() error %i\n", errStat);
       return NO;
   }

   ((FolderInfo*)catalogInfo.finderInfo)->finderFlags |= kIsInvisible;
   if (((FolderInfo*)catalogInfo.finderInfo)->finderFlags & kIsInvisible)
       return NO;

   NSString *hiddenFile = [NSString stringWithContentsOfFile:@"/.hidden"];
   NSArray *dotHiddens = [hiddenFile componentsSeparatedByString:@"\n"];

   if ([dotHiddens containsObject:[path lastPathComponent]])
       return NO;

   return YES;
}

int main(int argc, char *argv[]) {
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   NSString *path;

   if (argc != 2) {
       printf("must specify a path on the command line\n");
   }

   path = [[NSString alloc] initWithCString:argv[1]];

   if (isVisible(path)) {
       printf("visible\n");
   } else {
       printf("invisible\n");
   }

   [pool release];

   exit(0);
}
END hidden.m


--
Quote: "You need only reflect that one of the best ways to get
yourself a reputation as a dangerous citizen these days is to go about
repeating the very phrases which our founding fathers used in the
struggle for independence."--Charles Austin Beard
Web site: http://tylerriddle.com
AIM: The Masta Spice

Related mailsAuthorDate
mltesting for invisible files in a file browser Tyler Riddle Aug 9, 01:17
mlRe: testing for invisible files in a file browser stephen joseph but… Aug 9, 01:26
mlRe: testing for invisible files in a file browser Nick Zitzmann Aug 9, 01:58
mlRe: testing for invisible files in a file browser René van Amerongen Aug 9, 08:54
mlRe: testing for invisible files in a file browser Michele Balistreri Aug 9, 09:20
mlRe: testing for invisible files in a file browser Michele Balistreri Aug 9, 20:38