Discussion:
test for empty directory
(too old to reply)
Jim Nagel
2018-01-27 18:41:35 UTC
Permalink
I want to use filer_opendir on a certain directory, but only if
there's something in it -- no use opening it if it's empty.

There must be a simple way to test whether a directory is empty,
please? But I am an ignoramus. Thanks.
--
Jim Nagel www.archivemag.co.uk
"from" address is genuine but will change. website has current one.
|| See you at the show? www.riscos-swshow.co.uk Feb 24
John Williams (News)
2018-01-27 18:50:44 UTC
Permalink
Post by Jim Nagel
There must be a simple way to test whether a directory is empty,
please? But I am an ignoramus. Thanks.
Use the X prefix to avoid error reporting:

So X Filer_OpenDir will open a directory if it exists, but will do nothing
if it doesn't.

It'll still open it if it exists but is empty!

If that's no good, try this from BASIC:

DEF FN_objectpresent(fullpath$)
SYS"OS_File",23,fullpath$ TO present%,,,,,,objftype%
=present%
REM case present% of 0=absent 1=file 2=directory 3=image file

Check for the presence of the directory object, and then for anything
inside it.

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/
Brian Jordan
2018-01-27 19:37:17 UTC
Permalink
Post by Jim Nagel
I want to use filer_opendir on a certain directory, but only if
there's something in it -- no use opening it if it's empty.
There must be a simple way to test whether a directory is empty,
please? But I am an ignoramus. Thanks.
I do something like this to check for a new postscript file arriving in a
directory called $.!Myfiles.Printer_Out -

*ifthere $.!Myfiles.Printer_Out.* then filer_opendir
$.!Myfiles.Printer_Out

Seems to work for me in a little routine which, at its simplest, opens
the directory when I print a new postscript file ready for me to ftp to
my printer.
--
_____________________________________________________________________

Brian Jordan
RISC OS 5.23 on Raspberry Pi
_____________________________________________________________________
Jim Nagel
2018-01-27 22:59:23 UTC
Permalink
ifthere $.!Myfiles.Printer_Out.* then filer_opendir $.!Myfiles.Printer_Out
Elegant-- just that wildcard asterisk! Why didn't I thinkathat?

Thanks.
--
Jim Nagel www.archivemag.co.uk
"from" address is genuine but will change. website has current one.
|| See you at the show? www.riscos-swshow.co.uk Feb 24
j***@mdfs.net
2018-01-30 22:59:20 UTC
Permalink
Post by Jim Nagel
There must be a simple way to test whether a directory is empty,
please? But I am an ignoramus. Thanks.
OSGBPB 9/10/11/12 to scan directory contents. Ask for one entry starting
at the beginning, if you get one entry, the directory is not empty.
(Baring atomicity of operations, etc.)

Loading...