Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #5546 > unrolled thread

Testing for the presence of a file

Started byGraham Pickles <graham@durain.uk>
First post2018-10-08 12:35 +0100
Last post2018-10-23 07:43 +0100
Articles 14 — 6 participants

Back to article view | Back to comp.sys.acorn.programmer


Contents

  Testing for the presence of a file Graham Pickles <graham@durain.uk> - 2018-10-08 12:35 +0100
    Re: Testing for the presence of a file Alan Adams <alan@adamshome.org.uk> - 2018-10-08 12:50 +0100
      Re: Testing for the presence of a file Bob Latham <bob@sick-of-spam.invalid> - 2018-10-08 13:17 +0100
        Re: Testing for the presence of a file Alan Adams <alan@adamshome.org.uk> - 2018-10-08 14:24 +0100
        Re: Testing for the presence of a file Bob Latham <bob@sick-of-spam.invalid> - 2018-10-08 14:22 +0100
    Re: Testing for the presence of a file "John Williams (News)" <UCEbin@tiscali.co.uk> - 2018-10-08 14:42 +0100
      Re: Testing for the presence of a file Graham Pickles <graham@durain.uk> - 2018-10-09 09:33 +0100
        Re: Testing for the presence of a file "John Williams (News)" <UCEbin@tiscali.co.uk> - 2018-10-09 23:59 +0100
    Re: Testing for the presence of a file "John Williams (News)" <UCEbin@tiscali.co.uk> - 2018-10-08 14:50 +0100
      Re: Testing for the presence of a file "John Williams (News)" <UCEbin@tiscali.co.uk> - 2018-10-08 14:53 +0100
      Re: Testing for the presence of a file jgh@mdfs.net - 2018-10-21 19:57 -0700
        Re: Testing for the presence of a file jgh@mdfs.net - 2018-10-21 20:00 -0700
    Re: Testing for the presence of a file jgh@mdfs.net - 2018-10-21 19:55 -0700
      Re: Testing for the presence of a file Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-10-23 07:43 +0100

#5546 — Testing for the presence of a file

FromGraham Pickles <graham@durain.uk>
Date2018-10-08 12:35 +0100
SubjectTesting for the presence of a file
Message-ID<70cfbe4357.graham@graham.durain.uk>
I'm having a senior moment!  What is the simplest method of determining
in a Basic (RiscOs 4.02) program whether a named file exists in a
particular directory?

e.g. A file called test might/might not exist in my <Data$Dir>
directory. If it exists then I wish to remove it but don't want to
create an error if it doesn't exist!

Regards to all,

-- 
Graham Pickles
If you can't convince them confuse them. (Harry S. Truman)

[toc] | [next] | [standalone]


#5547

FromAlan Adams <alan@adamshome.org.uk>
Date2018-10-08 12:50 +0100
Message-ID<3b32c04357.Alan.Adams@ArmX6.adamshome.org.uk>
In reply to#5546
In message <70cfbe4357.graham@graham.durain.uk>
          Graham Pickles <graham@durain.uk> wrote:

> I'm having a senior moment!  What is the simplest method of determining
> in a Basic (RiscOs 4.02) program whether a named file exists in a
> particular directory?

> e.g. A file called test might/might not exist in my <Data$Dir>
> directory. If it exists then I wish to remove it but don't want to
> create an error if it doesn't exist!

> Regards to all,

X=OPENIN(TESTFILE$)
IF X=0 THEN
  PRINT "FILE "+TESTFILE$+" DOES NOT EXIST"
ELSE
  CLOSE#X
  PRINT "FILE "+TESTFILE$+" EXISTS"
ENDIF

Alan Adams, from Northamptonshire
alan@adamshome.org.uk
http://www.nckc.org.uk/

[toc] | [prev] | [next] | [standalone]


#5548

FromBob Latham <bob@sick-of-spam.invalid>
Date2018-10-08 13:17 +0100
Message-ID<5743c2acfdbob@sick-of-spam.invalid>
In reply to#5547
In article <3b32c04357.Alan.Adams@ArmX6.adamshome.org.uk>,
   Alan Adams <alan@adamshome.org.uk> wrote:
> In message <70cfbe4357.graham@graham.durain.uk>
>           Graham Pickles <graham@durain.uk> wrote:

> > I'm having a senior moment!  What is the simplest method of determining
> > in a Basic (RiscOs 4.02) program whether a named file exists in a
> > particular directory?

> > e.g. A file called test might/might not exist in my <Data$Dir>
> > directory. If it exists then I wish to remove it but don't want to
> > create an error if it doesn't exist!

> > Regards to all,

> X=OPENIN(TESTFILE$)
> IF X=0 THEN
>   PRINT "FILE "+TESTFILE$+" DOES NOT EXIST"
> ELSE
>   CLOSE#X
>   PRINT "FILE "+TESTFILE$+" EXISTS"
> ENDIF

Okay, complication of "in Basic" but isn't "OS_File 17" the way to go
with a bit of oscli perhaps?


Cheers,

Bob.

-- 
Bob Latham
Stourbridge, West Midlands

[toc] | [prev] | [next] | [standalone]


#5549

FromAlan Adams <alan@adamshome.org.uk>
Date2018-10-08 14:24 +0100
Message-ID<c5cec84357.Alan.Adams@ArmX6.adamshome.org.uk>
In reply to#5548
In message <5743c2acfdbob@sick-of-spam.invalid>
          Bob Latham <bob@sick-of-spam.invalid> wrote:

> In article <3b32c04357.Alan.Adams@ArmX6.adamshome.org.uk>,
>    Alan Adams <alan@adamshome.org.uk> wrote:
>> In message <70cfbe4357.graham@graham.durain.uk>
>>           Graham Pickles <graham@durain.uk> wrote:

>>> I'm having a senior moment!  What is the simplest method of determining
>>> in a Basic (RiscOs 4.02) program whether a named file exists in a
>>> particular directory?

>>> e.g. A file called test might/might not exist in my <Data$Dir>
>>> directory. If it exists then I wish to remove it but don't want to
>>> create an error if it doesn't exist!

>>> Regards to all,

>> X=OPENIN(TESTFILE$)
>> IF X=0 THEN
>>   PRINT "FILE "+TESTFILE$+" DOES NOT EXIST"
>> ELSE
>>   CLOSE#X
>>   PRINT "FILE "+TESTFILE$+" EXISTS"
>> ENDIF

> Okay, complication of "in Basic" but isn't "OS_File 17" the way to go
> with a bit of oscli perhaps?

And in the BASIC above, X=0 after the CLOSE, and near the start of the 
progrsamme
X=0
so that your error trap can include

IF X<>0 THEN CLOSE#X
without introducing an error into the error handler.

> Cheers,

> Bob.



-- 
Alan Adams, from Northamptonshire
alan@adamshome.org.uk
http://www.nckc.org.uk/

[toc] | [prev] | [next] | [standalone]


#5550

FromBob Latham <bob@sick-of-spam.invalid>
Date2018-10-08 14:22 +0100
Message-ID<5743c89728bob@sick-of-spam.invalid>
In reply to#5548
In article <5743c2acfdbob@sick-of-spam.invalid>,
   Bob Latham <bob@sick-of-spam.invalid> wrote:
> In article <3b32c04357.Alan.Adams@ArmX6.adamshome.org.uk>,
>    Alan Adams <alan@adamshome.org.uk> wrote:
> > In message <70cfbe4357.graham@graham.durain.uk>
> >           Graham Pickles <graham@durain.uk> wrote:

> > > I'm having a senior moment!  What is the simplest method of determining
> > > in a Basic (RiscOs 4.02) program whether a named file exists in a
> > > particular directory?

> > > e.g. A file called test might/might not exist in my <Data$Dir>
> > > directory. If it exists then I wish to remove it but don't want to
> > > create an error if it doesn't exist!

> > > Regards to all,

> > X=OPENIN(TESTFILE$)
> > IF X=0 THEN
> >   PRINT "FILE "+TESTFILE$+" DOES NOT EXIST"
> > ELSE
> >   CLOSE#X
> >   PRINT "FILE "+TESTFILE$+" EXISTS"
> > ENDIF

> Okay, complication of "in Basic" but isn't "OS_File 17" the way to go
> with a bit of oscli perhaps?

Actually, if all you need it to delete a file if it exists but not
error if it doesn't then "XOS_File" 6 looks the business. PRM says no
error if not present but it does error if locked.

Only needs R0 set to 6 and R1 a pointer to the file.

That must be pretty easy to setup from Basic I would imagine probably
OSCLI.

The other choice I think is OS_FSControl 27 which will delete if
locked if you set the flags.

I'm far from an expert on this, hope I'm not miles out.


Cheers,

Bob.

-- 
Bob Latham
Stourbridge, West Midlands

[toc] | [prev] | [next] | [standalone]


#5551

From"John Williams (News)" <UCEbin@tiscali.co.uk>
Date2018-10-08 14:42 +0100
Message-ID<5743ca65b9UCEbin@tiscali.co.uk>
In reply to#5546
In article <70cfbe4357.graham@graham.durain.uk>,
   Graham Pickles <graham@durain.uk> wrote:

> What is the simplest method of determining
> in a Basic (RiscOs 4.02) program whether a named file exists in a
> particular directory?

This simple function will not only tell you if it's there or not, but if it
is whether it's a file, directory, or image file:

  :
  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
  :

I use it quite a lot!

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/

[toc] | [prev] | [next] | [standalone]


#5556

FromGraham Pickles <graham@durain.uk>
Date2018-10-09 09:33 +0100
Message-ID<9701324457.graham@graham.durain.uk>
In reply to#5551
In message <5743ca65b9UCEbin@tiscali.co.uk>
          "John Williams (News)" <UCEbin@tiscali.co.uk> wrote:

>In article <70cfbe4357.graham@graham.durain.uk>,
>   Graham Pickles <graham@durain.uk> wrote:
>
>> What is the simplest method of determining
>> in a Basic (RiscOs 4.02) program whether a named file exists in a
>> particular directory?
>
>This simple function will not only tell you if it's there or not, but if it
>is whether it's a file, directory, or image file:
>
>  :
>  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
>  :
>
>I use it quite a lot!
>
>John
>
Many thanks. Of course. You reminded me. This is the method I have
adopted and it's ideal.

Regards,

-- 
Graham Pickles
I have not failed. I've just found 10000 ways that won't work. (Thomas
Edison)

[toc] | [prev] | [next] | [standalone]


#5557

From"John Williams (News)" <UCEbin@tiscali.co.uk>
Date2018-10-09 23:59 +0100
Message-ID<5744813e2fUCEbin@tiscali.co.uk>
In reply to#5556
In article <9701324457.graham@graham.durain.uk>,
   Graham Pickles <graham@durain.uk> wrote:
> >  :
> >  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
> >  :
> >
> >I use it quite a lot!
> >
> >John
> >
> Many thanks. Of course. You reminded me. This is the method I have
> adopted and it's ideal.

Thanks, Graham - it's not often I'm the chosen one!

But, to be fair, other contributions were equally good!

It's just that this one lends itself to being in a library of goodies!

Best wishes, 
 
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/

[toc] | [prev] | [next] | [standalone]


#5552

From"John Williams (News)" <UCEbin@tiscali.co.uk>
Date2018-10-08 14:50 +0100
Message-ID<5743cb2b2bUCEbin@tiscali.co.uk>
In reply to#5546
In article <70cfbe4357.graham@graham.durain.uk>,
   Graham Pickles <graham@durain.uk> wrote:

> If it exists then I wish to remove it but don't want to create an error
> if it doesn't exist!

Alternatively you could OSCLI (or WimpTask) "IfThere "+<path$>+"Wipe
"+<path$> it - that doesn't raise an error if it's not present!

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/

[toc] | [prev] | [next] | [standalone]


#5553

From"John Williams (News)" <UCEbin@tiscali.co.uk>
Date2018-10-08 14:53 +0100
Message-ID<5743cb70abUCEbin@tiscali.co.uk>
In reply to#5552
In article <5743cb2b2bUCEbin@tiscali.co.uk>,
   John Williams (News) <UCEbin@tiscali.co.uk> wrote:

> Alternatively you could OSCLI (or WimpTask) "IfThere "+<path$>+"Wipe
> "+<path$> it - that doesn't raise an error if it's not present!

Sorry - missed the "Then" out!

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/

[toc] | [prev] | [next] | [standalone]


#5559

Fromjgh@mdfs.net
Date2018-10-21 19:57 -0700
Message-ID<5d42b06a-716b-48ad-a2f5-770d318a1f37@googlegroups.com>
In reply to#5552
> > If it exists then I wish to remove it but don't want to create an error
> > if it doesn't exist!

*Remove or OS_File 7.

[toc] | [prev] | [next] | [standalone]


#5560

Fromjgh@mdfs.net
Date2018-10-21 20:00 -0700
Message-ID<bc332b54-7e00-4a25-b155-a63cf5fe5376@googlegroups.com>
In reply to#5559
> > > If it exists then I wish to remove it but don't want to create an error
> > > if it doesn't exist!
> 
> *Remove or OS_File 7.

Sorry, *Remove or OS_File 6.

SYS "XOS_File",6,objecttodelete$

OS_File 6 is defined to return R0=0 and no error if the object doesn't
exist, but it doesn't hurt to X-ify it in case the filing system is
broken.

[toc] | [prev] | [next] | [standalone]


#5558

Fromjgh@mdfs.net
Date2018-10-21 19:55 -0700
Message-ID<c2cd1e40-452d-483e-b8a4-d40c3b731915@googlegroups.com>
In reply to#5546
Why OS_File 17 or 23? What's wrong with good old OS_File 5?

SYS "OS_File",5,pathname$ TO objtype%

[toc] | [prev] | [next] | [standalone]


#5561

FromMatthew Phillips <spam2011m@yahoo.co.uk>
Date2018-10-23 07:43 +0100
Message-ID<b9a55d4b57.Matthew@sinenomine.freeserve.co.uk>
In reply to#5558
In message <c2cd1e40-452d-483e-b8a4-d40c3b731915@googlegroups.com>
 on 22 Oct 2018 jgh@mdfs.net wrote:

> Why OS_File 17 or 23? What's wrong with good old OS_File 5?
> 
> SYS "OS_File",5,pathname$ TO objtype%

Personally, I avoid OS_File 5 because it uses File$Path -- and I've always
wanted to know whether a file was really where I was looking for it, not
somewhere else.

But perhaps File$Path only comes into effect if you do not supply a full path
in R1, in which case it isn't an issue.

-- 
Matthew Phillips
Durham

[toc] | [prev] | [standalone]


Back to top | Article view | comp.sys.acorn.programmer


csiph-web