useing Metadata Lib, results coming back as 0

I’m using Shanes Metadata Lib to try and get all files in a folder that end with certain attributes, in the
test case it is

set searchString to "NLCSOPQ" --the actual file looks like this   9s-TS-NLCSOPQ.ps

i’m not quite sure why i’m getting zero returned, from the code below, cant see what I may have missed.

use script "Metadata Lib" version "2.0.0"
use scripting additions

set pathExtension to "ps"

set searchString to "NLCSOPQ" --the actual file looks like this   9s-TS-NLCSOPQ.ps

set searchPath to POSIX path of "/Users/BUDGIE/Desktop/TEST/"

set searchKey to quote & "*-" & searchString & "*." & pathExtension & quote

set theMetadata to perform search in folders {searchPath} predicate string "kMDItemFSName like[c] %@" search arguments {searchKey}

cheers

Metadata queries can’t use the like operator, you need to use ==, which supports wildcards. You also shouldn’t be quoting the search string.

Having said that, I’m not sure such a specific query is going to work. It’s going to be a little slower, but using FileManagerLib’s objects of with a result type of urls array and then using standard predicate filtering will be more reliable.

Thanks Shane
I used your suggestion, managed to cobble together a script from various other scripts which works well, cheers, not sure if this is as efficient as it can be, but it works well.

    makeMenu("/Users/BUDGIE/Desktop/TEST/")
    on makeMenu_(searchString)
    set searchStrings to {searchString}
    set srcFldrPath to POSIX path of ("/Users/BUDGIE/Desktop/TEST/")
    set srcFldrPath to current application's NSString's stringWithString:srcFldrPath
    set theNSFileManager to current application's NSFileManager's defaultManager()
    set theFiles to theNSFileManager's contentsOfDirectoryAtPath:srcFldrPath |error|:(missing value)
    set thePreds to {}
    repeat with aString in searchStrings
        set end of thePreds to (current application's NSPredicate's predicateWithFormat_("self contains %@", aString))
    end repeat
    set theFiles to theFiles's filteredArrayUsingPredicate:(current application's NSCompoundPredicate's andPredicateWithSubpredicates:thePreds)
    set fileList to (theFiles) as list
    set theList to fileList
    tell current application's NSSet to set theSet to setWithArray_(theList)
    tell current application's NSSortDescriptor to set theDescriptor to sortDescriptorWithKey_ascending_(missing value, true)
    set sortedList to theSet's sortedArrayUsingDescriptors_({theDescriptor})
log sortedList
    repeat with anItem in sortedList
    aPopupMenu's addItemWithTitle_(anItem)
    end
log theFiles
    end makeMenu:

I’m not sure about your sorting code. I suggest more like this:

set uniqueArray to (current application's NSSet's setWithArray:theList)'s allObjects()
set theDescriptor to current application's NSSortDescriptor's sortDescriptorWithKey:"path" ascending:true
set sortedList to uniqueArray's sortedArrayUsingDescriptors:{theDescriptor}