Discussion:
Using results of a directory cataloguing
(too old to reply)
x***@gmail.com
2018-06-11 03:13:23 UTC
Permalink
Target machine : BBC A3000, RO 3.1x, BASIC program, single tasking.

I want to get all the file names in a directory, to be able to further use these file names (to do batch processing).
Language : BASIC (prefered) or ASM.
What should I do, to get sthing like (I presume) a pointer to a list of all file names in a chosen directory ?

Thanks in advance for your help.
John Williams (News)
2018-06-11 07:38:31 UTC
Permalink
Post by x***@gmail.com
I want to get all the file names in a directory, to be able to further
use these file names (to do batch processing). Language : BASIC
(prefered) or ASM. What should I do, to get sthing like (I presume) a
pointer to a list of all file names in a chosen directory ?
I quite often use EnumDir to a file as a quick and easy way of doing this:

EnumDir <Prune$Dir>.^ <Prune$Dir>.list
SetType <Prune$Dir>.list text

in the Run file of the application. Then you simply have a sequential text
list to process as you wish. Of course all objects are listed, including
directories and the application itself.

The above is from my Prune program used to delete excess back-ups.

Hope this helps,

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Alan Adams
2018-06-11 09:20:16 UTC
Permalink
Post by John Williams (News)
Post by x***@gmail.com
I want to get all the file names in a directory, to be able to further
use these file names (to do batch processing). Language : BASIC
(prefered) or ASM. What should I do, to get sthing like (I presume) a
pointer to a list of all file names in a chosen directory ?
EnumDir <Prune$Dir>.^ <Prune$Dir>.list
SetType <Prune$Dir>.list text
in the Run file of the application. Then you simply have a sequential text
list to process as you wish. Of course all objects are listed, including
directories and the application itself.
The above is from my Prune program used to delete excess back-ups.
Hope this helps,
John
Within BASIC you can use OS_GBPB to return either one or a list of
files to process. Asking for one at a time can make your program
simpler.

Use OS_GBPB 12 with R3 set to 1 (fetch 1 entry). On return the block
will include at offset 16 the object type - 1=file, 2=directory,
3=application directory.
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
j***@mdfs.net
2018-06-12 09:55:29 UTC
Permalink
It's risky to demand all the filenames in a directory all at once
(on any system) as you don't know beforehand how many you'll get,
so could potentially fetch four billion filenames. It's best to
get them one at a time and do whatever processing you want to do
on each one as you go.

The following is portable across any platform with an Acorn/BBC API:
http://beebwiki.mdfs.net/Scanning_Directories_(Reading_Directory_Entries)
Martin
2018-06-12 12:34:04 UTC
Permalink
On 12 Jun in article
Post by j***@mdfs.net
It's risky to demand all the filenames in a directory all at once
(on any system) as you don't know beforehand how many you'll get,
so could potentially fetch four billion filenames. It's best to
get them one at a time and do whatever processing you want to do
on each one as you go.
Asking for *all* the files is obviously not a good thing to do,
but asking for a number with limits is fine.
Post by j***@mdfs.net
http://beebwiki.mdfs.net/Scanning_Directories_(Reading_Directory_Entries)
On a BBC computer, using CALL &FFD1 to call the old BBC MOS style
OSGBPB routine would be the (only) way to go. However, the OP is
using RISC OS v3.1, and I would suggest the new-style SYS "OS_GBPB"
would be much better even though CALL &FFD1 may still work.

Using SYS "OS_GBPB" with r0=9 to 12, you can decide how much
information you want to be returned for each file, and the maximum
number of files to be returned in one call. They may both depend on
on the buffer size that you can make available. The more files at
once, the faster it will be ... but does make the program slightly
more complex.

In BASIC the simple code is based on...
max% = ??? :REM max files that might be returned
blen% = ??? :REM to hold approx max% entries
DIM buf% blen%
next% = 0
REPEAT
SYS "OS_GBPB",xx,dir$,buf%,max%,next%,blen%,name$ TO,,,read%,next%
IF read% <> 0 THEN
process buffer
ENDIF
UNTIL next% = -1
--
Martin Avison
Note that unfortunately this email address will become invalid
without notice if (when) any spam is received.
druck
2018-06-12 17:25:27 UTC
Permalink
Post by j***@mdfs.net
It's risky to demand all the filenames in a directory all at once
(on any system) as you don't know beforehand how many you'll get,
so could potentially fetch four billion filenames. It's best to
get them one at a time and do whatever processing you want to do
on each one as you go.
Attempting to reading all entries is perfectly OK, as long as...
Post by j***@mdfs.net
http://beebwiki.mdfs.net/Scanning_Directories_(Reading_Directory_Entries)
...you use a sensible API. The above is the old Beeb style and shouldn't
be used by any new code. Instead see:-

https://www.riscosopen.org/wiki/documentation/show/OS_GBPB

Use reason code 9,10,11 or 12 to read entries into a buffer of size you
specify. If its big enough it will get all entries in one go. (Don't use
8 as you can't specify the size).

Of course if the buffer isn't big enough, you need to repeat the call
until all entries are read. To simplify matters people often only use a
buffer large enough for one entry, and always repeat the call.

---druck
x***@gmail.com
2018-06-16 04:04:30 UTC
Permalink
Post by druck
Post by j***@mdfs.net
It's risky to demand all the filenames in a directory all at once
(on any system) as you don't know beforehand how many you'll get,
so could potentially fetch four billion filenames. It's best to
get them one at a time and do whatever processing you want to do
on each one as you go.
Attempting to reading all entries is perfectly OK, as long as...
Post by j***@mdfs.net
http://beebwiki.mdfs.net/Scanning_Directories_(Reading_Directory_Entries)
...you use a sensible API. The above is the old Beeb style and shouldn't
be used by any new code. Instead see:-
https://www.riscosopen.org/wiki/documentation/show/OS_GBPB
Use reason code 9,10,11 or 12 to read entries into a buffer of size you
specify. If its big enough it will get all entries in one go. (Don't use
8 as you can't specify the size).
Of course if the buffer isn't big enough, you need to repeat the call
until all entries are read. To simplify matters people often only use a
buffer large enough for one entry, and always repeat the call.
---druck
Thanks to all of you for your help.
I think I'll have some time to try some of your solutions this week end, and will come back if I need more help.
That's for my project of porting SOTB to the Archie (free advertising to my YT channel : SOTB Archie playlist is here : https://www.youtube.com/view_all_playlists )
x***@gmail.com
2018-06-16 04:20:10 UTC
Permalink
Thanks to all of you for your help.
I think I'll have some time to try some of your solutions this week end, and will come back if I need more help.
That's for my project of porting SOTB to the Archie
(free advertising to my YT channel : SOTB Archie playlist is here :
https://www.youtube.com/user/Archimedes75009/playlists )

Loading...