Dyalog APL - Parsing a vector of strings and appending a string to each vector.

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

  •  05-07-2021
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top