العثور على المجلدات غير مرئية مع الضوء عن طريق إنشاء NSPredicate مع NSMetadataQuery [مغلقة]

StackOverflow https://stackoverflow.com/questions/1441466

سؤال

وأنا بناء على NSmetaDataQuery للعثور على المجلدات غير مرئية (مثل ".myInvisibleFolder").

ولسوء الحظ، لا يبدو الضوء ليتم تحديد المجلدات التي تبدأ ب "."، حتى عندما تدرج تحديدا في المسند.

ما يفيد وما لا يفيد العمل

والبحث عن أي أعمال اسم الملف غير invisable.

والأعمال محتوى البحث (kMDItemTextContent).

لا يوجد ملف بدأت مع "". وجدت من أي وقت مضى. دوما بإرجاع 0 النتائج.

وكما يعمل اختبار، والبحث عن محتوى غير مرئية في الباحث.

وماذا أفعل الخطأ؟ هل هناك طريقة أخرى للعثور على المجلدات غير مرئية؟

والرمز:

- (void)searchForMyInvisableFolders{
    self.query = [[[NSMetadataQuery alloc] init] autorelease];

    // To watch results send by the query, add an observer to the NSNotificationCenter
    NSNotificationCenter *nf = [NSNotificationCenter defaultCenter];
    [nf addObserver:self selector:@selector(queryNote:) name:nil object:self.query];

    // Sort results by file name
    [self.query setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:(id)kMDItemFSName ascending:YES] autorelease]]];

    [self.query setDelegate:self];

    //Create a predicate to search for file name
    NSPredicate* predicate = [NSPredicate predicateWithFormat:@" (kMDItemFSName == '.myInvisibleFolder')"];

    //Create a predicate to search for invisible files
    NSPredicate* invisablePredicate = [NSPredicate predicateWithFormat:@"kMDItemFSInvisible == YES"];

    //Compound predicate
    NSPredicate* compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:predicate, invisiblePredicate, nil]]; 

    // Set it to the query.
    [self.query setPredicate:compoundPredicate];           

    // Start it.
    [self.query startQuery]; 

}   
هل كانت مفيدة؟

المحلول

والتعليمات البرمجية الخاصة بك يعمل تماما بالنسبة لي إذا قمت بتغيير المسند الأول إلى:

[NSPredicate predicateWithFormat:@" (kMDItemFSName == '.DS_Store')"];

هل مجلد غير مرئية الخاص بك يسمى حقا ".myInvisableFolder" (لاحظ الخطأ الإملائي الخاص بك غير مرئية)؟

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top