0

Learning kdb+q. Without loss of generality, let's say if I have a list of file paths and wants to open each one of them, but I want to make sure Q opens whatever it exists. Say if one of the file paths doesn't exist, then continue to process others.

I know protected evaluation can let me handle error @[open_many_files_func; files; errhandler]. But how to make it not fail in the middle and continue with the rest?

Gary
  • 1,828
  • 1
  • 20
  • 27

2 Answers2

2

You can use 'each' to iterate over the files

@[open_many_files_func; ; errhandler] each files
Adam Bonham
  • 615
  • 4
  • 7
1

If it's just existance of the file that you're checking for (and not that the function fails due to a problem with the file), then you could also use the key function to check the existance of the file.

q)system "ls"
"file1"
"file2"
"file4"
q)b: a where count each a: key each `:file1`:file2`:file3`:file4
`:file1`:file2`:file4

Once you have the list of files, you can just do

open_many_files_func each b

https://code.kx.com/q/ref/key/