Dyalog APL - Parsing a vector of strings and appending a string to each vector.
-
05-07-2021 - |
Question
I have a vector of input data given by A <-- Files.Dir '...directory'
and this returns a vector of all the files in that directory.
However, the path contains only the file names, not the full paths. What I want to do is to append the path stored in B
to each of the elements in A
.
How in the hell do I do this?
La solution
You can use the catenate primitive function (dyadic ,) with the each primitive operator (dyadic ¨). An example would look like:
a
file00 file01 file02 file03
b
C:\Path\To\Files
(⊂b,'\'),¨a
C:\Path\To\Files\file00 C:\Path\To\Files\file01 C:\Path\To\Files\file02 C:\Path\To\Files\file03
Assuming a windows file system.
Note that catenate requires both its arguments to have the same shape, or be scalars. That is why we had to enclose (⊂) the character vector b so that it became a scalar containing a character vector.
Also note that for completeness I used catenate to add a trailing backslash
⊂b,'\'
The parentheses were only present to ensure that this was run first as APL always evaluates from right to left with the exception of brackets.