22 January 2023, 14:00 | #1 |
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
OS 3.1 ARexx and/or AmigaDOS Get File List As Array
Not sure if this is the correct place for this question so apologies if not and feel free to move and/or point me in the right direction.
I'm using Workbench 40.42 with KS 3.1 on an emulated A1200 with 2MB chip and 8MB Fast RAM . I'm trying to write an ARexx script to manipulate some files but I've fallen at the first hurdle. I know I can simply use Dir or Dir Files in DOS to get a list of the files or directories contained in a volume, but I don't know how to take that output and, say, either feed it into an array or pass it directly to an ARexx script as a parameter (such that each file name occupies one element of the params array). I could use ARexx to do the whole thing without having to use DOS but for the life of me I can't find out something as simple as how to list files in a directory using ARexx I've searched and searched through all the documentation I can find for both ARexx and AmigaDOS but I can't find a solution. I can't help but feel like I'm missing something really basic or obvious. Can anyone help please? |
22 January 2023, 18:38 | #2 |
Zone Friend
Join Date: Mar 2004
Location: Middle Earth
Age: 40
Posts: 2,127
|
Code:
LIST filedirectory FILES LFORMAT="%s" >>ram:filesa sort FROM ram:filesa to ram:filesb I'm still learning AREXX myself, hopefully Thomas will help you, he helped me with my problem. |
22 January 2023, 20:53 | #3 |
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
Nice. I'll give that a try as soon as I get chance and see what I can do with it. Thank you.
I only discovered ARexx existed about 3 days ago. I'm not new to programming or scripting - I work with Java, C++ (occasionally), Python, .NET, Windows batch and the Unix shell as part of my job - but I just can't seem to work out what I'm doing with ARexx and AmigaDOS at all lol |
22 January 2023, 21:28 | #4 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,303
|
You can use RexxTricks http://aminet.net/package/util/rexx/RexxTricks_386 or RexxArp http://aminet.net/package/util/rexx/ral3p8 for easy/comfort file access. There is also SHOWDIR() from rexxsupport.library to use.
You need this documentation: http://aminet.net/search?name=arexxguide |
22 January 2023, 21:49 | #5 | ||
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
Quote:
Quote:
|
||
23 January 2023, 13:39 | #6 |
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
Erm... okay... falling at small hurdles again
I can't get any of the functions contained in RexxTricks to work. No matter what I do I get a "Function not found" error every time. I used the installer to install RexxTricks and it says it was installed successfully. I've confirmed rexxtricks.library is present in LIBS: I've gone through the Readme several times looking for a solution but nothing is mentioned in there. I've re-downloaded and re-installed in case it was a corrupted download/install but still no joy. I even copy/pasted one of their examples verbatim to make sure I wasn't mis-typing something but that didn't help either. What am I doing wrong? As an aside, is it a thing in Amigaland to not document/poorly document things? This isn't the first time I've come across a dearth of documentation for something since getting back into the Amiga. It's really frustrating. |
23 January 2023, 14:22 | #7 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,303
|
Ok, this information is a bit hidden. At least if you don't know where to look. The solution is more or less simple. You have to open (edit: open is not quite right. The library is added to the resident library list.) the/a library first. Then you can use it's functions.
Usually, Amiga OS comes with an ARexx book. On my OS 3.1 book it is chapter 5.6 (5-46) "Functions of REXXSupport.Library" (the library comes with the OS). The example program 14 OpenLibrary.rexx shows how to open a library. It is more or less the same with any other library. See also ADDLIB(). For AmigaGuide2 documentation have a look at function ADDLIB() and part "function library. It contains more information then you need. Hope it helps to shrink your frustration. You know the beginning is always a bit harder. Last edited by daxb; 23 January 2023 at 17:32. |
23 January 2023, 16:04 | #8 |
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
Brilliant, thank you! Pointing me in that direction has solved the problem...
...but now I've stumbled and fallen at the very next step too So now I'm getting "Host environment not found" which, according to what documentation I can find, is something to do with a missing message port corresponding to the host address string. Great. I understand what that means but not how to go about fixing it... aaaaand as you can probably guess the documentation is silent on the matter (or at least is keeping it's secrets well hidden as I can't find the answer anywhere and I've really tried to find it!!). Any suggestions how I can solve this latest issue or where I might be able to find more information on it? |
23 January 2023, 17:05 | #9 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
One strength of ARexx (or Rexx in general) is to be able to send commands to applications. This way you can combine the features of multiple apps, giving more benefit as you had with each app seperately.
In order to receive commands the app has to open an ARexx port. Rexx also calls this a function host. Then a Rexx script can send commands to the port (a.k.a. host). To define the destination port name you use the ADDRESS command. You can either use ADDRESS <portname> as a standalone command, then all comming commands are sent to <portname>. Or you can put a command behind ADDRESS <portname>, then only that command is sent to the port. All text parts in a script which do not begin with a known keyword are considered commands to be sent to a function host. The error you get just means that the port you addressed does not exist, in other words, the app is not running. This could mean you made a typo in the port name. Or you didn't yet set up a port name and made a typo in an ARexx command (which means it is unknown to ARexx and thus considered a command to be sent to the current function host). Or you tried to address an app which is not (yet) running. Note that port names are case sensitive. If you want to address a port which contains lower case characters, you have to enclose it in quotes because Rexx converts all names to upper case. Or if the port name is the name of a variable you used before, you also have to enclose it in quotes because otherwise to contents of the variable would be used. Without context it is difficult to help. You have to quote at least the line in error and the ADDRESS command which was executed before. |
23 January 2023, 18:09 | #10 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,303
|
What thomas wrote. It is easier to help if you post the script or at least the part/source of the error. Maybe it is too early to mention but the "trace" command/function is helpful to solve errors. I usually open the trace console with the command TCO (TCC to close) and put a "trace r" (for results) or "trace i" (for more output) at start of the script or somewhere else.
Don't care to much. When I started with ARexx I stumbled about the same problems. Using ADDRESS wrong is just normal. |
23 January 2023, 19:25 | #11 | |
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
Quote:
What I mean by that is: taking my fist steps in ARexx, as with most languages, I started with "Hello world" - I didn't need to use ADDRESS() for that as it was literally a simple script that wasn't communicating with anything, if that makes sense? It looks exactly like this: Code:
/* HelloWorld.rexx */ SAY `Hello World!` So, no use of ADDRESS() anywhere and no complaints of a missing host environment. Now, using a copy/pasted example from the RexxTricks guide (below for reference) I'm getting the aforementioned "Host environment not found" error. As far as I'm aware though the below code isn't trying to communicate with anything, is it? If so, where? Shouldn't SAY output the same way as it did in the above working code? Why is it different here? Code:
/* ** Read a directory and all subdirectories and display the ** complete path of all entries, don't display icons */ IF GETDIR('DEVS:','~(#?.info)','stemvar','FILES','PATH','SUBDIRS') THEN DO SAY 'Number of entries:' stemvar.0 DO i = 1 TO stemvar.0 SAY stemvar.i END END I've also written a couple of scripts that do some basic string manipulation - so a little more involved than "Hello World!" - and they work just fine: no use of ADDRESS() anywhere and no "missing host" error messages. I'm not currently trying to pass anything to nor communicate with any other applications... am I? I'm so confused!! |
|
23 January 2023, 20:05 | #12 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,303
|
Hmm... the GETDIR() example works fine here (did a copy paste). If rexxtricks.library isn't in the library list then I get error 15 Function not found. So it seems you do something else wrong or there is some unknown cause.
What you write about ADDRESS is right. If you don't talk to any other port then REXX (default port) you don't need it. |
24 January 2023, 08:46 | #13 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
Quote the complete error message. It points you to the offending line in your script. It even prints it to the console.
Like daxb indicated, in order to use functions of an external library you have to load this library first. If GETDIR is not recognised as a library function, it tries to call a script called GETDIR or GETDIR.rexx in the path pointed to by the Rexx: assign or in the current directory. The error message also indicates in which script the error occurred and which script called it. |
27 January 2023, 00:37 | #14 | ||
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
Sorry for the late reply I've been busy with work unfortunately.
Quote:
Code:
+++ Error 13 in line 5: Host environment not found Command returned 10/13: Host environment not found Quote:
|
||
27 January 2023, 15:12 | #15 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,303
|
I think it is time to post the whole script in code tags. So we can check if the script itself is ok or not at least.
For testing you could try SHOWDIR() from rexxsupport.library to see if it works at least or you get the same error. For quick debugging small things it is useful to test it direct in a shell. E.g.: Code:
rx "call GETDIR(<...>)" or rx "say SHOWDIR(<...>)" |
30 January 2023, 11:46 | #16 |
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
For completeness here's the script that was giving me problems, but it's a moot point now as the problem was elsewhere. I don't know what it was exactly, but I did a complete, clean reinstall of WB3.1 and ARexx and now the below script is working as expected. Looks like it was an issue with the environment or install or something like that.
Code:
/* Test2.rexx */ ADDLIB("rexxtricks.library",0,-30,0) IF GETDIR('DEVS:','~(#?.info)','stemvar','FILES','PATH','SUBDIRS') THEN DO SAY 'Number of entries:' stemvar.0 DO i = 1 TO stemvar.0 SAY stemvar.i END END Thanks for all the responses though, I really appreciate it |
30 January 2023, 15:52 | #17 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,303
|
Good that if now works for you. I would at least add a CALL in front of ADDLIB() but more important IMHO is to do some error checking like it is done in the Amiga ARexx book chapter 5.6 (5-46). In the case of case it could save some bug hunting.
|
30 January 2023, 21:32 | #18 |
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
I hear ya. Normally I would always include some error checking but I was just trying this as a 'Hello World' kind of thing to get off the ground before writing some proper code (or trying to at least ) and figured it would do as I'd copy/pasted it directly from the library's own example code.
Thanks again for the advice |
31 January 2023, 00:25 | #19 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
I don't think this is the wrong place to ask, but if you have scripting- or ARexx-specific questions, you can also ask in this subforum.
|
01 February 2023, 15:49 | #20 |
Amigas: A500+ A600 A1200
Join Date: Dec 2022
Location: Liverpool, UK
Age: 42
Posts: 55
|
That's a useful resource for sure. Thanks for the heads-up
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Saving an array to File | LeCaravage | Coders. Blitz Basic | 4 | 14 February 2021 16:37 |
Any way to get a list of AREXX commands available for a program? | MickGyver | support.Apps | 11 | 15 January 2018 22:39 |
Parsing an HTML file in Arexx | Gundam | Coders. General | 7 | 09 April 2014 00:16 |
A-Z list of erroneus TOSEC AmigaDOS disks | andreas | project.TOSEC (amiga only) | 10 | 04 December 2009 08:06 |
|
|