• 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
testing for invisible files in a file browser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

testing for invisible files in a file browser


  • Subject: testing for invisible files in a file browser
  • From: "Tyler Riddle" <email@hidden>
  • Date: Tue, 8 Aug 2006 16:17:42 -0700

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 _______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: testing for invisible files in a file browser
      • From: Nick Zitzmann <email@hidden>
    • Re: testing for invisible files in a file browser
      • From: "stephen joseph butler" <email@hidden>
  • Prev by Date: Re: Crashing on all relevant exceptions
  • Next by Date: Re: testing for invisible files in a file browser
  • Previous by thread: NSXMLDocument and fetching attributes with name spaces?
  • Next by thread: Re: testing for invisible files in a file browser
  • Index(es):
    • Date
    • Thread