I have not had time to test this with lots of files BUT you can try it
(I think it will be much faster than what your doing in your code BUT I
may be wrong)
anyway what I did was create a simple shell script that you call with a
FULLY pathed file name (unless you are in the directory that you want to
check) and it will return a 1 if it exists or a 0 if it does not
Below is the shell script
*#!/usr/bin/ksh
if (test -e $1)
then
echo '1'
else
echo '0'
fi*
*exit
<end shell script>
and below is a sample run
$ ./testit ./testit1 <== this file does NOT exist
0
$ ./testit ./testit <== this file DOES exist
1
now all you have to in your basic code is
CMD = 'sh -c "testit ':FILE.TO.TEST:'"'
EXECUTE CMD CAPTURING RESULTS
one thing you may have to do is remove any unix line feeds before you
compare the results, if RESULTS = 1 does not match and you know the
file exists
IF RESULTS = 1 THEN
PRINT 'file exists ....'
END ELSE
PRINT ' file does not exist s....'
END
well you get the idea, I think it will be much faster
hope that helps
dougc
*
ps
you may have to modify the first line of the shell script if your ksh is
in a different location (which ksh will tell you where its located)
Scott Ballinger wrote:
> I have a standard subroutine that I use in UV BASIC when I need to check for
> the existence (or non-existance) of a unix file:
>
> FILE.TEST.SUB
> 0001 SUB(FILENAME,ANS)
> 0002 * return ans = 1 if filename exists
> 0003 * redirect to bit bucket to suppress 'not on file' msg
> 0004 * filename includes full path to file
> 0005 EXECUTE "SH -c 'ls -d ":FILENAME:" 2> /dev/null'" CAPTURING XXX
> 0006
> 0007 FN = FILENAME
> 0008 CONVERT "\" TO "" IN FN ;* in case we escaped any special characters
> 0009
> 0010 IF XXX<1> EQ FN THEN ANS = 1 ELSE ANS = 0
> 0011
> 0012 RETURN
> 0013
>
> It works fine, but seems pretty slow, particularly if I am churning though
> thousands of tests (like from a big select list).
> Can anyone suggest a faster/more efficient way to test if a unix level file
> exists from inside UV BASIC ?
>
> Thanks,
> /Scott Ballinger
> Pareto Corporation
> Edmonds WA USA
> 206 713 6006
> -------
> u2-users mailing list
> [email protected]
> To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/