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
How to check for existence of an URL?
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13318
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to check for existence of an URL?
Try opening it and if it fails, it doesn’t exist?
Follow us on Twitter @IHSEViews
Re: How to check for existence of an URL?
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
-
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13318
- Joined: Tue Sep 16, 2008 5:38 pm
Re: How to check for existence of an URL?
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
Follow us on Twitter @IHSEViews
Re: How to check for existence of an URL?
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
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
Who is online
Users browsing this forum: No registered users and 53 guests