Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.acorn.programmer > #5676 > unrolled thread
| Started by | usenet@garethlock.com |
|---|---|
| First post | 2019-01-21 13:48 -0800 |
| Last post | 2019-01-27 23:33 +0000 |
| Articles | 15 — 9 participants |
Back to article view | Back to comp.sys.acorn.programmer
Traversing a directory in BASIC... usenet@garethlock.com - 2019-01-21 13:48 -0800
Re: Traversing a directory in BASIC... Gerald Holdsworth <nospam@hollypops.co.uk> - 2019-01-21 22:18 +0000
Re: Traversing a directory in BASIC... Steve Fryatt <news@stevefryatt.org.uk> - 2019-01-21 22:44 +0000
Re: Traversing a directory in BASIC... usenet@garethlock.com - 2019-01-21 15:02 -0800
Re: Traversing a directory in BASIC... Steve Fryatt <news@stevefryatt.org.uk> - 2019-01-21 23:59 +0000
Re: Traversing a directory in BASIC... usenet@garethlock.com - 2019-01-21 18:12 -0800
Re: Traversing a directory in BASIC... Matthew Phillips <spam2011m@yahoo.co.uk> - 2019-01-22 08:14 +0000
Re: Traversing a directory in BASIC... Martin <News03@avisoft.f9.co.uk> - 2019-01-21 23:04 +0000
Re: Traversing a directory in BASIC... usenet@garethlock.com - 2019-01-21 15:53 -0800
Re: Traversing a directory in BASIC... Alan Adams <alan@adamshome.org.uk> - 2019-01-22 12:26 +0000
Re: Traversing a directory in BASIC... Martin <News03@avisoft.f9.co.uk> - 2019-01-22 16:30 +0000
Re: Traversing a directory in BASIC... jgh@mdfs.net - 2019-01-23 05:26 -0800
Re: Traversing a directory in BASIC... Alan Adams <alan@adamshome.org.uk> - 2019-01-23 15:01 +0000
Re: Traversing a directory in BASIC... David Higton <dave@davehigton.me.uk> - 2019-01-24 14:35 +0000
Re: Traversing a directory in BASIC... Richard Porter <dontusethis@address.uk.invalid> - 2019-01-27 23:33 +0000
| From | usenet@garethlock.com |
|---|---|
| Date | 2019-01-21 13:48 -0800 |
| Subject | Traversing a directory in BASIC... |
| Message-ID | <5551f8d2-bbd0-4d15-aa64-bc799be24414@googlegroups.com> |
I'm trying to write a routine that returns a list of items, both files and directories, in a given directory. Think I might have hit on something using OS_GBPB, but one has to supply the number of items to read. Been trying OS_FSControl 28 to return a count before calling OS_GBPB, can get this to count files, but not directories... Has anyone come across a better way of doing this??
[toc] | [next] | [standalone]
| From | Gerald Holdsworth <nospam@hollypops.co.uk> |
|---|---|
| Date | 2019-01-21 22:18 +0000 |
| Message-ID | <qLKdnWvr6tKD2NvBnZ2dnUU78YPNnZ2d@brightview.co.uk> |
| In reply to | #5676 |
On 21/01/2019 21:48, usenet@garethlock.com wrote: > I'm trying to write a routine that returns a list of items, both files and directories, in a given directory. Think I might have hit on something using OS_GBPB, but one has to supply the number of items to read. Been trying OS_FSControl 28 to return a count before calling OS_GBPB, can get this to count files, but not directories... > > Has anyone come across a better way of doing this?? > Take a peek at: http://www.reptonresourcepage.co.uk/Download.php?item=DecodingRepton.pdf in the chapter "Useful Programs". Here I've written a program, in BASIC, to iterate through a directory tree and find a specific type of file. The actual code for doing this was written, IIRC, by Alex Von Someron (of Aleph One) - but for some reason I haven't credited him (oops...must correct that one). I actually found it in a book I've got...somewhere! You can also download the program here: http://www.reptonresourcepage.co.uk/Download.php?item=Editcodes.zip Cheers, Gerald. -- gerald at hollypops dot co dot uk Repton Resource Page www.reptonresourcepage.co.uk
[toc] | [prev] | [next] | [standalone]
| From | Steve Fryatt <news@stevefryatt.org.uk> |
|---|---|
| Date | 2019-01-21 22:44 +0000 |
| Message-ID | <mpro.plpduj01xvpnf01pb.news@stevefryatt.org.uk> |
| In reply to | #5676 |
On 21 Jan, usenet@garethlock.com wrote in message
<5551f8d2-bbd0-4d15-aa64-bc799be24414@googlegroups.com>:
> I'm trying to write a routine that returns a list of items, both files and
> directories, in a given directory. Think I might have hit on something
> using OS_GBPB, but one has to supply the number of items to read. Been
> trying OS_FSControl 28 to return a count before calling OS_GBPB, can get
> this to count files, but not directories...
>
> Has anyone come across a better way of doing this??
Isn't this one an FAQ by now?
OS_GBPB >= 9 returns telling you how many items have been read, and whether
there any any more items to read. You repeatedly call it, holding state
across calls, processing the results each time (IF ANY ARE RETURNED -- it's
quote valid for (next% <> -1) AND (read% = 0)) and continuing until it
reports no more results to come.
size% = 1024
DIM buffer% size%-1
next% = 0
read% = 0
REPEAT
SYS "OS_GBPB", 10, dir$, buffer%, objects_to_read%, next%, size%, 0
TO ,,,read%, next%
IF read% > 0 THEN
FOR item% = 0 TO read% - 1
REM Process the read items here
NEXT item%
ENDIF
UNTIL next% = -1
Do NOT assume that next% has any meaning beyond "-1" or "not -1".
--
Steve Fryatt - Leeds, England
http://www.stevefryatt.org.uk/
[toc] | [prev] | [next] | [standalone]
| From | usenet@garethlock.com |
|---|---|
| Date | 2019-01-21 15:02 -0800 |
| Message-ID | <1736875c-babb-4d19-88f7-6f6863d5da8d@googlegroups.com> |
| In reply to | #5678 |
That's alright if you know the value of objects_to_read%. I seem to be coming a cropper when passing a nonsense number here when trying to read all the objects in the current directory whilst not knowing how many this is...
[toc] | [prev] | [next] | [standalone]
| From | Steve Fryatt <news@stevefryatt.org.uk> |
|---|---|
| Date | 2019-01-21 23:59 +0000 |
| Message-ID | <mpro.plphal02u95ej01pb.news@stevefryatt.org.uk> |
| In reply to | #5679 |
On 21 Jan, usenet@garethlock.com wrote in message
<1736875c-babb-4d19-88f7-6f6863d5da8d@googlegroups.com>:
> That's alright if you know the value of objects_to_read%. I seem to be
> coming a cropper when passing a nonsense number here when trying to read
> all the objects in the current directory whilst not knowing how many this
> is...
objects_to_read% is a maximum. The call returns the number of items read in
the variable that I called read%, and that's what the IF statement was for:
you check how many items have come back, and process them (using a FOR loop
or whatever).
Rememeber that the call can return zero items even though there are more to
come. You muct check the number of items returned each time and skip if
there are none, but continue polling until next% is returned as -1.
--
Steve Fryatt - Leeds, England
http://www.stevefryatt.org.uk/
[toc] | [prev] | [next] | [standalone]
| From | usenet@garethlock.com |
|---|---|
| Date | 2019-01-21 18:12 -0800 |
| Message-ID | <da0a6ea9-9d73-4c78-bb8a-fffda39b63d9@googlegroups.com> |
| In reply to | #5682 |
Just out of interest, what exactly would cause read% to return zero whilst next% <> -1 I.e there are still entries to read... Curiosity...
[toc] | [prev] | [next] | [standalone]
| From | Matthew Phillips <spam2011m@yahoo.co.uk> |
|---|---|
| Date | 2019-01-22 08:14 +0000 |
| Message-ID | <a7fa427a57.Matthew@sinenomine.freeserve.co.uk> |
| In reply to | #5683 |
In message <da0a6ea9-9d73-4c78-bb8a-fffda39b63d9@googlegroups.com> on 22 Jan 2019 usenet@garethlock.com wrote: > Just out of interest, what exactly would cause read% to return zero whilst > next% <> -1 I.e there are still entries to read... Curiosity... It depends entirely on the implementation of the underlying file system which may not be FileCore. You should also not assume that the value in F4 increases by one each time the information for a single file is read. Some applications come unstuck by making this assumption, which does not hold true for FAT32FS, for example. To give you an example of why a filing system might return no entries, let me introduce you to the CP/M disc format, for which I wrote CPMFS. The CP/M format was a predecessor of MSDOS and is the origin of the 8 + 3 (name + extension) style of filename that persisted until Windows 95. The directory on the disc is held in a block of a number of consecutive sectors. Each directory entry is 32 bytes long. The first 16 bytes contains a byte that can indicate the file is deleted, the filename, and a directory entry count. The following 16 bytes point to the sectors on the disc where the file is found. The way I implemented CPMFS, R4 corresponds to the directory entry to read next, so when you enter with R4 = 0 it reads the first entry. Suppose you ask for four to be read each time. On exit R4 will equal 4, then 8, then 12, and eventually will be set to -1 when there are no more to read. But it's possible that all the first four directory entries are for deleted files, in which case no results will be returned. Also, if a file is larger than 16K it will require more than one directory entry to record the allocated sectors, so any of the directory entries that handle the overflow will not be reported when reading the files via OS_GBPB. At least, that's one possible implementation. It's certainly how I handled what R4 meant, but it may be that I just looped round until I had read the number of objects requested in R3, and the exit value in R4 would have gone up by more than four in these cases. I can't remember. FAT32FS also implements R4 in a similar way. This means you cannot safely take 1 off R4 to step back by 1 in the directory listing. Another reason for returning zero in R3 might be if the filing system is waiting for a network device to respond and has had to time out to keep the machine responsive. -- Matthew Phillips Durham
[toc] | [prev] | [next] | [standalone]
| From | Martin <News03@avisoft.f9.co.uk> |
|---|---|
| Date | 2019-01-21 23:04 +0000 |
| Message-ID | <577a109ff4News03@avisoft.f9.co.uk> |
| In reply to | #5676 |
On 21 Jan in article <5551f8d2-bbd0-4d15-aa64-bc799be24414@googlegroups.com>, <usenet@garethlock.com> wrote: > I'm trying to write a routine that returns a list of items, both > files and directories, in a given directory. Think I might have hit > on something using OS_GBPB, but one has to supply the number of > items to read. Been trying OS_FSControl 28 to return a count before > calling OS_GBPB, can get this to count files, but not directories... > Has anyone come across a better way of doing this?? Nope. OS_GBPB is the way to go. The number of objects to read on entry is the *maximum* to read in one go. The actual number that has been read is returned, and it may be zero. To go to the end of a directory you need to repeat until r4=-1. A simple structure for the code can be seen in the OS StrongHelp manual, if you do not have the PRMs. -- Martin Avison Note that unfortunately this email address will become invalid without notice if (when) any spam is received.
[toc] | [prev] | [next] | [standalone]
| From | usenet@garethlock.com |
|---|---|
| Date | 2019-01-21 15:53 -0800 |
| Message-ID | <9de49902-5704-436c-be24-065e70e886ec@googlegroups.com> |
| In reply to | #5680 |
Thanks to you all... I was already about half way there whilst messing around earlier. That little lot enabled me to get it working...
[toc] | [prev] | [next] | [standalone]
| From | Alan Adams <alan@adamshome.org.uk> |
|---|---|
| Date | 2019-01-22 12:26 +0000 |
| Message-ID | <d81f5a7a57.Alan.Adams@ArmX6.adamshome.org.uk> |
| In reply to | #5680 |
In message <577a109ff4News03@avisoft.f9.co.uk>
Martin <News03@avisoft.f9.co.uk> wrote:
> On 21 Jan in article
> <5551f8d2-bbd0-4d15-aa64-bc799be24414@googlegroups.com>,
> <usenet@garethlock.com> wrote:
>> I'm trying to write a routine that returns a list of items, both
>> files and directories, in a given directory. Think I might have hit
>> on something using OS_GBPB, but one has to supply the number of
>> items to read. Been trying OS_FSControl 28 to return a count before
>> calling OS_GBPB, can get this to count files, but not directories...
>> Has anyone come across a better way of doing this??
> Nope. OS_GBPB is the way to go.
> The number of objects to read on entry is the *maximum* to read in
> one go.
So the simplest way for you to use this is to set the number to read to 1,
then you either get a file/directory, or nothing.
> The actual number that has been read is returned, and it may be zero.
> To go to the end of a directory you need to repeat until r4=-1.
> A simple structure for the code can be seen in the OS StrongHelp
> manual, if you do not have the PRMs.
--
Alan Adams, from Northamptonshire
alan@adamshome.org.uk
http://www.nckc.org.uk/
[toc] | [prev] | [next] | [standalone]
| From | Martin <News03@avisoft.f9.co.uk> |
|---|---|
| Date | 2019-01-22 16:30 +0000 |
| Message-ID | <577a7070fcNews03@avisoft.f9.co.uk> |
| In reply to | #5685 |
On 22 Jan in article <d81f5a7a57.Alan.Adams@ArmX6.adamshome.org.uk>, Alan Adams <alan@adamshome.org.uk> wrote: > In message <577a109ff4News03@avisoft.f9.co.uk> > Martin <News03@avisoft.f9.co.uk> wrote: > > On 21 Jan in article > > <5551f8d2-bbd0-4d15-aa64-bc799be24414@googlegroups.com>, > > <usenet@garethlock.com> wrote: > >> I'm trying to write a routine that returns a list of items, both > >> files and directories, in a given directory. Think I might have > >> hit on something using OS_GBPB, but one has to supply the number > >> of items to read. Been trying OS_FSControl 28 to return a count > >> before calling OS_GBPB, can get this to count files, but not > >> directories... > >> Has anyone come across a better way of doing this?? > > Nope. OS_GBPB is the way to go. The number of objects to read on > > entry is the *maximum* to read in one go. > So the simplest way for you to use this is to set the number to > read to 1, then you either get a file/directory, or nothing. That will work. However, if you have a directory with lots of entries, it is better to create a buffer that can take many entries so that the SWI is called fewer times. Note that the Action you use (9, 10, 11 or 12) dictates the amount of information returned, from just filename to 29 bytes+filename, so a 2048 byte buffer can hold from roughly 180 to 60 entries (assuming file names averaging 10 characters). Note that if you specify a larger number to read than will fit in the buffer then OS_GBPB is savvy enough to stop before the buffer is overrun, so the number to read can be set high. > > The actual number that has been read is returned, and it may be > > zero. To go to the end of a directory you need to repeat until > > r4=-1. > > A simple structure for the code can be seen in the OS StrongHelp > > manual, if you do not have the PRMs. That structure will just work. Anything else is very liable to cause problems in some way or another. -- Martin Avison Note that unfortunately this email address will become invalid without notice if (when) any spam is received.
[toc] | [prev] | [next] | [standalone]
| From | jgh@mdfs.net |
|---|---|
| Date | 2019-01-23 05:26 -0800 |
| Message-ID | <8c3bb862-c4f2-4c8c-8424-2f3f9cf0577f@googlegroups.com> |
| In reply to | #5686 |
The difficulty so many people seem to have in comprehending the documentation for OSGBPB seems so prevalent, it's a fequently frequently asked question, surely there's demo code somewhere? http://beebwiki.mdfs.net/Scanning_Directories_(Reading_Directory_Entries)
[toc] | [prev] | [next] | [standalone]
| From | Alan Adams <alan@adamshome.org.uk> |
|---|---|
| Date | 2019-01-23 15:01 +0000 |
| Message-ID | <ff15ec7a57.Alan.Adams@ArmX6.adamshome.org.uk> |
| In reply to | #5687 |
In message <8c3bb862-c4f2-4c8c-8424-2f3f9cf0577f@googlegroups.com>
jgh@mdfs.net wrote:
> The difficulty so many people seem to have in comprehending the
> documentation for OSGBPB seems so prevalent, it's a fequently
> frequently asked question, surely there's demo code somewhere?
> http://beebwiki.mdfs.net/Scanning_Directories_(Reading_Directory_Entries)
The confusion is probably because OS_GBPB can do so many different things,
and each thing has options within it.
It won't be "an example", it's likely to be a booklet of them.
--
Alan Adams, from Northamptonshire
alan@adamshome.org.uk
http://www.nckc.org.uk/
[toc] | [prev] | [next] | [standalone]
| From | David Higton <dave@davehigton.me.uk> |
|---|---|
| Date | 2019-01-24 14:35 +0000 |
| Message-ID | <658f6d7b57.DaveMeUK@my.inbox.com> |
| In reply to | #5687 |
In message <8c3bb862-c4f2-4c8c-8424-2f3f9cf0577f@googlegroups.com>
jgh@mdfs.net wrote:
>The difficulty so many people seem to have in comprehending the
>documentation for OSGBPB seems so prevalent, it's a fequently
>frequently asked question
The answer to the questions seems to boil down to:
RTFM.
Do what TFM says, not some other interpretation.
Dave
[toc] | [prev] | [next] | [standalone]
| From | Richard Porter <dontusethis@address.uk.invalid> |
|---|---|
| Date | 2019-01-27 23:33 +0000 |
| Message-ID | <3c4b2a7d57.news@user.minijem.plus.com> |
| In reply to | #5676 |
The date being 21 Jan 2019, usenet@garethlock.com decided to write: > I'm trying to write a routine that returns a list of items, both files and > directories, in a given directory. Think I might have hit on something > using OS_GBPB, but one has to supply the number of items to read. Been > trying OS_FSControl 28 to return a count before calling OS_GBPB, can get > this to count files, but not directories... > Has anyone come across a better way of doing this?? If you have !SiteMatch you can copy the way it recursively scans a directory. That's the one bit I haven't tampered with since I took it over. much.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.sys.acorn.programmer
csiph-web