New Native File Quad Functions in v15
4 posts
• Page 1 of 1
New Native File Quad Functions in v15
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?
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
You have to use the Wildcard variant to get the contents of a directory, so
So a very simple function that recursively lists all the items in a directory and its subdirectories might look something like:
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
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←{Clearly this function needs enhancing, but it shows the basic technique that can be used.
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>
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/
-
AndyS|Dyalog - Posts: 257
- Joined: Tue May 12, 2009 6:06 pm
Re: New Native File Quad Functions in v15
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
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
BTW,
This was written for SALT but works for normal usage too.
With -recursive (or -rec) it works recursively.
]??list for details
- Code: Select all
]list \folder -extension
This was written for SALT but works for normal usage too.
With -recursive (or -rec) it works recursively.
]??list for details
- DanB|Dyalog
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group