Search code examples
kdb

getting the path name files in a directory in q


I am using q to get all the files listed in that directory:

key `:Dname

and then try to filter out the the ones that start with numbers as:

key `:Dname like "[0-9]"

but the like part does not quite work. I tried get as well since I like the path to include the directory that the file is in.


Solution

  • Keep in mind that q evaluate expressions from right to left. Your code here will first evaluate

    `:Dname like "[0-9]"
    

    and apply key to the result.

    You want something closer to

    key[`:Dname] like "[0-9]"
    

    But to get what you want you'll have to add a wildcard to the pattern string that you're supplying and apply not to the result

    not key[`:Dname] like "[0-9]*"
    

    This will give you a boolean vector, to return the list of files you want use where and index:

    key[`:Dname] where not key[`:Dname] like "[0-9]*"