Page 1 of 1

How to check for existence of an URL?

Posted: Tue Jul 31, 2018 12:21 am
by mamo
Dear Eviewers,

I use Eviews 10+.
Would anybody have a suggestion how to check for the existence of an url?
(for instance: excel file with US GDP data at the BEA, "https://www.bea.gov/national/xls/gdplev.xlsx")
It seems that the Eviews-function "@fileexist" does not work with urls.

Best, mamo

Re: How to check for existence of an URL?

Posted: Tue Jul 31, 2018 6:49 am
by EViews Gareth
Try opening it and if it fails, it doesn’t exist?

Re: How to check for existence of an URL?

Posted: Tue Jul 31, 2018 7:49 am
by mamo
Well I am looking for sth which can be applied in a program, for instance
%url="https://www.bea.gov/national/xls/gdplev.xlsx"
if @urlexist(%url) then
'do something
else
'do something else
endif

Re: How to check for existence of an URL?

Posted: Tue Jul 31, 2018 9:04 am
by EViews Gareth

Code: Select all

setmaxerrs 2
wfopen "https://www.bea.gov/national/xls/gdplev.xlsx"
if @errorcount>0 then
 'do something
else
 ' do something else
endif

Re: How to check for existence of an URL?

Posted: Wed Aug 01, 2018 3:56 am
by mamo
Many thanks, this is a workable patch-around.
For completeness and for whom it may be useful, I provide below a subroutine with improved code (disabling also log-messages, and resetting the error counter).
However, this work-around requires reading in the respective file linked to by the url. If the file is large, this wastes considerable computing time.
Hence, I'd like to suggest to the EVIEWS team to consider implementing a more efficient approach in a function named like '@urlexist' in upcoming versions.

mamo


Code: Select all

' %url="http://www.euklems.net/TCB/2017/US_output_17i.xlsx"  ' smaller file; routine works reasonably fast
%url="https://www.bea.gov/national/xls/gdplev.xlsx"   ' large file; routine take a lot of time for a simple check!
!checkurl=0
call checkurl(%url, !checkurl)
statusline !checkurl

subroutine checkurl(string %url, scalar !check)
setmaxerrs 2
logmode -e
!check=0
wfopen %url
if @errorcount=0 then
   !check=1   
   wfclose
endif
clearerrs
setmaxerrs 1
logmode 2
endsub