New Native File Quad Functions in v15

General APL language issues

New Native File Quad Functions in v15

Postby paulmansour on Wed Apr 13, 2016 5:43 pm

Version 15 has a bunch of new quad functions for dealing with native files and folders. In particular ⎕MKDIR, ⎕NDELETE, and ⎕NINFO. This looked like a good opportunity to remove dependence on the windows scripting host and .NET, and make my app run on linux, etc.

However, as I go through my code there are still some things I can't do. In particular, get a list of all the files and the sub folders given a directory, something like ⎕DIR. A simple list of names in a folder would go a long way, as then ⎕Info could be used to determine what is file and what is a subfolder.

Question: Should this or something like it be added to the quad functions? Are there more of critical importance? Is the list endless or is there a reasonable set that would cover just about or most everything?

I'm sure everyone has a library of their own stuff to do this using various techniques ... what would everyone think would be a critical set?
paulmansour
 
Posts: 420
Joined: Fri Oct 03, 2008 4:14 pm

Re: New Native File Quad Functions in v15

Postby AndyS|Dyalog on Thu Apr 14, 2016 8:42 am

You have to use the Wildcard variant to get the contents of a directory, so
      0 (⎕ninfo⍠1)'./*'
will return the names of all of the items in ".".

So a very simple function that recursively lists all the items in a directory and its subdirectories might look something like:
      lsr←{
0=≢⍵:0 2⍴0 ''
l←⍉↑1 0(⎕NINFO⍠1)⍵,'/*'
d←(1=l[;1])/l[;2]
0=≢d:l
l⍪⊃⍪/∇¨d
}
lsr'.'
1 ./bin
2 ./bin/qa.any
2 ./bin/sedcore
<etc><etc>
Clearly this function needs enhancing, but it shows the basic technique that can be used.

These file handling functions have been designed to be portable .. they should work the same on all platforms that Dyalog runs on. They have been designed to be called from your code, rather than at the 6-space prompt, and to be platform-neutral.

That is why we very specifically did not use ⎕DIR .. with my UNIX hat on I would argue that in that case the system function should be called ⎕LS !

Another useful little one-liner is
      ⊃1 ⎕nparts''
which returns the working directory of the current process:
      ⊃1 ⎕nparts''      ⍝ On my AIX box
/home/andys/
⊃1 ⎕nparts'' ⍝ and on my laptop
C:/Users/andys.DYALOG/Desktop/
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm

Re: New Native File Quad Functions in v15

Postby paulmansour on Thu Apr 14, 2016 10:43 am

Andy,

Thanks.... obviously I did a terrible job reading the documentation! (I think I see "variant" and my eyes glaze over). Anyway this is great stuff, thanks.

Also, my Rumba project loaded up and ran perfectly in V15.

Paul
paulmansour
 
Posts: 420
Joined: Fri Oct 03, 2008 4:14 pm

Re: New Native File Quad Functions in v15

Postby DanB|Dyalog on Thu Apr 14, 2016 7:21 pm

BTW,
Code: Select all
]list \folder -extension
(or -e) will list ALL files in a given folder.
This was written for SALT but works for normal usage too.
With -recursive (or -rec) it works recursively.

]??list for details
DanB|Dyalog
 


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest